【问题标题】:Execute INTO to accept NULL values执行 INTO 以接受 NULL 值
【发布时间】:2017-07-11 16:02:42
【问题描述】:

我在互联网上搜索过,找不到任何有关如何使用 EXECUTE INTO 的信息或示例,包括何时声明可能什么也不返回。

我收到了错误

EXECUTE 的查询字符串参数为空

我尝试过使用 IF EXISTS() 创建一个包含计数和一大堆事物的语句。此时我觉得我在绕圈子。令人沮丧!

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

【问题讨论】:

标签: postgresql insert plpgsql execute


【解决方案1】:

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

错误:EXECUTE 的查询字符串参数为空

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

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

【讨论】:

    猜你喜欢
    • 2020-07-06
    • 2018-08-29
    • 1970-01-01
    • 2016-10-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-25
    相关资源
    最近更新 更多