sql - PostgreSQL 错误 : set-returning functions are not allowed in CASE

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

我尝试在 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 

出现错误:

set-returning functions are not allowed in CASE

最佳答案

改用横向连接:

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 ;

关于sql - PostgreSQL 错误 : set-returning functions are not allowed in CASE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47574330/

相关文章:

sql - PostgreSQL 中的并行 unnest() 和排序顺序

sql - JOIN on 集合返回函数结果

mysql - 部分搜索mysql字段中的破折号值

java - 这个 SQL 语句可以在 JPQL + 指南中使用吗?

postgresql - 如何在 postgresql 中以弹性方式删除触发器

sql - 获取字符串中的每个 <tag> - stackexchange 数据库

sql - 打印 MySQL 数据库(800 多个表)的 ER 图

sql - 从 Rails 模式文件中删除 SQL 代码

Django 本地 flavor 选择小部件列表

php - 在 Ubuntu10 中安装 pdo_pgsql 不工作