-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstored_procedures.sql
More file actions
67 lines (52 loc) · 996 Bytes
/
stored_procedures.sql
File metadata and controls
67 lines (52 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
drop table if exists accounts;
create table accounts(
id serial primary key,
full_name varchar(20) not null,
balance dec(10,2) not null
);
insert into accounts (
full_name, balance
)
values (
'abc', 1000
),
(
'def', 2000
);
select * from accounts;
create or replace procedure transaction (
sender int,
receiver int,
amount dec
)
language plpgsql
as $$
begin
update accounts
set balance = balance - amount
where id = sender;
update accounts
set balance = balance + amount
where id = receiver;
commit;
end;$$;
call transaction(1, 2, 100);
create or replace procedure transaction (
sender int,
receiver int,
amount dec
)
language plpgsql
as $$
begin
update accounts
set balance = balance - amount
where id = sender;
update accounts
set balance = balance + amount
where id = receiver;
commit;
end;$$;
call transaction(1, 2, 50);
call transaction(2, 1, 50);
select * from accounts;