Postgres: Using function variable names in pgsql function
I have written a pgsql function along the lines of what's shown below. How can I get rid of the $1, $2, etc. and replace them开发者_运维技巧 with the real argument names to make the function code more readable?
Regards
Peter
CREATE OR REPLACE FUNCTION InsertUser (
UserID UUID,
FirstName CHAR(10),
Surname VARCHAR(75),
Email VARCHAR(75)
)
RETURNS void
AS
$$
INSERT INTO "User" (userid,firstname,surname,email)
VALUES ($1,$2,$3,$4)
$$
LANGUAGE SQL;
You must declare it before you use it at the declare area. For exemple :
DECLARE
v_UserID alias for $1;
v_FirstName alias for $2;
v_Surname alias for $3;
v_Email alias for $4;
BEGIN
$$
END
Try this thing
CREATE or replace FUNCTION delhi(nam varchar, mm numeric , nn numeric ) RETURNS integer
AS $$
begin
insert into exe ( name , m1 ,m2 ) values ( nam, mm , nn );
-- see here column name is not like function argument name , so that it wont say error
return 1;
end ;
$$
LANGUAGE plpgsql;
Function calling :
select delhi ( 'first value', 2,3 ) ;
精彩评论