执行 INTO 接受 NULL 值

Execute INTO to accept NULL values

我已经在 Internet 上进行了搜索,但找不到有关如何使用 EXECUTE INTO 的任何信息或示例,包括语句可能 return 什么都没有的情况。

我遇到了错误

EXECUTE 的查询字符串参数为空

我试过使用 IF EXISTS() 创建一个包含计数和整个 things.At 的语句,这一点我觉得我在兜圈子。令人沮丧!

是否有默认方法来执行此操作?

这里execute format('select 1 where false') into t不会给t放任何东西,所以稍后execute t会给

ERROR: query string argument of EXECUTE is null

如此简单的合并将有所帮助:

t=# do $$
declare t text;
begin
execute format('select 1 where %L',false) into t;
execute coalesce(t,'select now()') into t;
raise '%',t;
end;
$$
;
ERROR:  2017-07-11 16:11:03.149521+00
Time: 0.349 ms