如何创建不返回任何内容的函数
问题描述:
我想用pl/pgsql
编写一个函数.
我正在使用 PostgresEnterprise Manager v3 并使用shell来创建函数,但是我必须在shell中定义返回类型.如果未定义返回类型,则无法创建函数.
I want to write a function with pl/pgsql
.
I'm using PostgresEnterprise Manager v3 and using shell to make a function, but in the shell I must define return type. If I don't define the return type, I'm not able to create a function.
如何创建没有返回结果的函数,即创建新表的函数?
How can create a function without return result, i.e a Function that creates a new table?
答
使用RETURNS void
如下:
CREATE FUNCTION stamp_user(id int, comment text) RETURNS void AS $$
#variable_conflict use_variable
DECLARE
curtime timestamp := now();
BEGIN
UPDATE users SET last_modified = curtime, comment = comment
WHERE users.id = id;
END;
$$ LANGUAGE plpgsql;