ScA*_*er2 12 postgresql stored-procedures plpgsql
如何在postgres中编写一个不返回值的简单存储过程?当我调用存储过程时,即使使用void返回类型,我也会返回一行.
CREATE FUNCTION somefunc(in_id bigint) RETURNS void AS $$
BEGIN
DELETE from test_table where id = in_id;
END;
$$ LANGUAGE plpgsql;
Run Code Online (Sandbox Code Playgroud)
小智 6
你可以通过滥用set-returns函数来实现"没有返回":
功能简单:
create function x () returns setof record as $$
begin
return;
END;
$$ language plpgsql;
Run Code Online (Sandbox Code Playgroud)
现在你可以:
# select x();
x
---
(0 rows)
Run Code Online (Sandbox Code Playgroud)
万一它不适合你(对不起,我使用8.5),尝试这种方法:
# create function x (OUT o1 bool, OUT o2 bool) returns setof record as $$
begin
return;
END;
$$ language plpgsql;
CREATE FUNCTION
Run Code Online (Sandbox Code Playgroud)
参数无关紧要,但是:
现在你可以:
# select * from x();
o1 | o2
----+----
(0 rows)
Run Code Online (Sandbox Code Playgroud)
你做得很好.你不需要添加任何其他东西.
该行的结果为null,因此它是一个void返回.
我不认为你可以做些什么.检查我的虚函数所有这些都和你的一样.
返回void as $$,代码块中没有return语句.
| 归档时间: |
|
| 查看次数: |
14970 次 |
| 最近记录: |