I am getting the below error when I try to create either a stored procedure or a stored function in PGADMIN4. How can I fix it:
ERROR: syntax error at or near "procedure"
LINE 1: create or replace procedure transfer(
The code to create the tables:
drop table if exists accounts;
create table accounts (
id int generated by default as identity,
name varchar(100) not null,
balance dec(15,2) not null,
primary key(id)
);
insert into accounts(name,balance) values('Bob',10000);
insert into accounts(name,balance) values('Alice',10000);
Error is received after I add the below stored procedure:
create or replace procedure transfer(
sender int,
receiver int,
amount dec
)
language plpgsql
as $$
begin
-- subtracting the amount from the sender's account
update accounts
set balance = balance - amount
where id = sender;
-- adding the amount to the receiver's account
update accounts
set balance = balance + amount
where id = receiver;
commit;
end;$$