PostgreSQL错误:在CASE中不允许设置返回函数

6yjfywim  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(2)|浏览(220)

我试着在PostgreSQL 10中运行这个查询:

  1. select e.errordescription,
  2. CASE
  3. WHEN e.reworkempid is not null THEN get_empname(e.reworkempid)
  4. else null
  5. end
  6. from error_log_gs e
  7. where e.qcworkpackageid=3012175 and e.logno=1

字符串
得到错误:
CASE中不允许使用集返回函数

tjrkku2a

tjrkku2a1#

使用lateral join代替:

  1. select e.errordescription, ge.name
  2. from error_log_gs e left join lateral
  3. get_empname(e.reworkempid) ge(name)
  4. on e.reworkempid is not null
  5. where e.qcworkpackageid = 3012175 and e.logno = 1 ;

字符串

kqqjbcuj

kqqjbcuj2#

我遇到的确切错误是,0A000:在CASE中不允许设置返回函数
在调查时,发现该语法在Postgres 9.6版中有效,但在11版中无效。
为了克服这个问题,我又添加了一个CTE(公共表表达式),如下所示,解决了我的问题。

  1. cte as
  2. (
  3. select string_to_array("StartDate", ',') as "S1_StartDate",
  4. string_to_array("EndDate", ',') as "S1_EndDate",
  5. case when "FlatDisc" is null then '{0}' when "FlatDisc" ='' then '{0}' else string_to_array("FlatDisc", ',') end as "S1_FlatDisc"
  6. from TABLE_XYZ
  7. )
  8. ,cte2 as
  9. (
  10. select unnest("S1_StartDate") as "S_StartDate",
  11. unnest("S1_EndDate") as "S_EndDate",
  12. unnest("S1_FlatDisc") as "S_FlatDisc"
  13. from cte
  14. )
  15. select * from cte2

字符串

展开查看全部

相关问题