【发布时间】:2020-05-02 09:55:03
【问题描述】:
在 postgres sql 函数中,我只想在 CTE 返回任何行时运行function_update。此查询适用于此。
with common_table as (select 1 where true) select function_update('value') from common_table
但是,如果我还想返回 function_update 是否更新了任何行,那么它不起作用。该函数确实返回 true 或 false,具体取决于 CTE 是否返回任何行,但 function_update 似乎没有运行。
with common_table as (select 1 where true) select exists(select function_update('value') from common_table)
function_update 就像update mytable set column1 = 'changed' where column2 = arg_value 这样简单。 mytable 在我运行上面的第一个查询而不是第二个查询时得到更新。为什么这没有按预期工作,我需要更改什么?
【问题讨论】:
-
function_update()返回什么? -
这是一个带有
returns void的函数。不返回任何内容,只是更新一行。
标签: sql postgresql common-table-expression