gpt4 book ai didi

postgresql - Postgres 调用 void 函数

转载 作者:行者123 更新时间:2023-11-29 11:40:39 25 4
gpt4 key购买 nike

我有一个 void plsql 函数:

CREATE OR REPLACE FUNCTION do_something(p_id BIGINT) 
RETURNS void
AS $$
BEGIN
insert ....
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

我想从另一个 plsql 函数调用这个函数,但是在这样的查询中:

SELECT  do_something(m.id) 
FROM MyTable m
WHERE m.IsActive;

当我运行 sproc 时,我得到:

ERROR: query has no destination for result data HINT: If you want to discard the results of a SELECT, use PERFORM instead.

是否可以在 select 语句中调用 void 函数?

最佳答案

HINT: If you want to discard the results of a SELECT, use PERFORM instead.

PERFORM  do_something(m.id) 
FROM MyTable m
WHERE m.IsActive;

PERFORMSELECT 的 PL/PgSQL 替代品,当您想要丢弃结果时。它不能在 PL/PgSQL 之外使用。有关详细信息,请参阅手册。

关于postgresql - Postgres 调用 void 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22804152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com