Reputation: 157
I am new to POSTGRES and currently exploring how to create and execute stored procedures. I was trying a simple example with conditional constructs and got stuck with an error :(
create procedure learnpostgre(x integer, y integer)
language plpgsql
as $$
if x > y
then
raise 'X is greater'
end if
$$;
The error I am getting is 'syntax error at or near if'. I saw similar issues on SO and tried wrapping my code block under do block but faced the same error message for 'Do'. I am running my code in pgadmin4 and postgres version is 14.X
Upvotes: 1
Views: 320
Reputation: 4806
You're missing begin
and end
and a few semicolons. This should work:
create procedure learnpostgre(x integer, y integer)
language plpgsql
as $$
begin
if x > y
then
raise 'X is greater';
end if;
end
$$
Upvotes: 1