sql - Syntax error with pgSQL, using functions and if else -
i'm practicing little bit postgresql, i'm creating simple function inserts row table depending on value of variable 'num'. however, when try create function following error in pgadmin iii:
"an error has occured: error: syntax error @ or near if line 3: if num = 1 then"
this code:
create function "elseif"(in num integer) returns void $body$ if num = 1 insert "accounts"( "email", "password") values ('email1', 'password1'); else insert "accounts"( "email", "password") values ('email2', 'password2'); end if; $body$ language plpgsql volatile not leakproof; alter function public."elseif"(in integer) owner repository;
any possible solution? in advance!
pl/pgsql must wrapped in begin ... end
block.
... returns void $body$ begin if num = 1 ... end if; end; $body$ ....
Comments
Post a Comment