--mybase is your database name. If public, remove it.
CREATE OR REPLACE FUNCTION mybase.my_new_rotine(numeric)
RETURNS numeric AS
$BODY$
--here, get the first variable from function
declare id numeric= $1;
begin
--return the number
return id;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
2 回答
您可以't use DECLARE in a SQL statement. What you want to do requires plpgsql. danielarend'的答案是对的,但您可能想要探索DO(https://www.postgresql.org/docs/current/static/sql-do.html),它可以让您编写adhoc plpgsql而无需定义函数 .
您必须将代码放在用户定义的函数中 . 它不适用于sql窗口 . 下面的示例是一个函数,它返回您发送的数字 . 变量
那么,你可以在sql窗口上使用它,如下所示:
将返回1