如何编写不返回任何内容的postgres存储过程? [英] How do I write a postgres stored procedure that doesn't return anything?

查看:284
本文介绍了如何编写不返回任何内容的postgres存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在postgres中编写一个简单的存储过程,而该存储过程根本不返回任何值? 即使在我调用存储过程时返回类型为空,我也会返回单行.

How do I write a simple stored procedure in postgres that doesn't return a value at all? Even with a void return type when I call the stored procedure I get a single row back.

CREATE FUNCTION somefunc(in_id bigint) RETURNS void AS $$
BEGIN
   DELETE from test_table where id = in_id;
END;
$$ LANGUAGE plpgsql;

推荐答案

不是返回值的函数,而是您用来调用它的SELECT.如果它不返回任何行,则不会运行您的函数.

It's not the function that returns value, it's the SELECT you used to call it. If it doesn't return any rows, it doesn't run your function.

这篇关于如何编写不返回任何内容的postgres存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆