【问题标题】:PostgreSQL error: set-returning functions are not allowed in CASEPostgreSQL 错误:CASE 中不允许设置返回函数
【发布时间】:2017-11-30 13:11:15
【问题描述】:

我尝试在 PostgreSQL 10 中运行此查询:

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

得到错误:

CASE 中不允许设置返回函数

【问题讨论】:

  • 案例表达式,不是语句。
  • 错误对我来说似乎很清楚,你的问题是什么?
  • 实际上这个问题是不言而喻的,比神秘的错误信息更重要。 不清楚为什么 CASE 在其他用例中返回一个集合,而在其他用例中它似乎是逐行操作(例如,您在搜索中遇到的每个 CASE 教程)。幸运的是@linoff 明白这一点。

标签: sql postgresql set-returning-functions postgresql-10


【解决方案1】:

改用lateral join

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    • 2019-02-22
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    • 2015-04-23
    相关资源
    最近更新 更多