【发布时间】:2020-05-01 19:16:25
【问题描述】:
在 SQL 函数中,如果我这样做,我可以返回一个布尔值
with myquery as (delete from mytable where id = 'value1' returning 1)
select exists (select * from another_function('value2') where (select count(*) from myquery) > 0);
但在 plpgsql 函数中它不起作用并给出错误query has no destination for result data。
在此函数中,如果实际从mytable 中删除了任何行,我想执行another_function。问题是我在重复整个select exists 部分,因为我在多个函数中使用它。
是否可以将更多的逻辑移到another_function 中?这样我就可以做这样的事情了?
with myquery as (delete from mytable where id = 'value1' returning 1)
select * from another_function('value2', myquery)
如何将 CTE 传递给函数,这样我就不需要在每次调用 another_function 时都重复 select exists 和 where (select count(*) from myquery) > 0)?
【问题讨论】:
-
我只是感到困惑。
another_function在一种情况下接受一个参数,在另一种情况下,第二个参数在哪里......什么?CTE?一个元组?我想你应该问一个新问题,其中包含有关您想要完成的任务的更多细节。
标签: sql postgresql plpgsql common-table-expression