-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexample.setup.sql
More file actions
26 lines (23 loc) · 721 Bytes
/
example.setup.sql
File metadata and controls
26 lines (23 loc) · 721 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
create table orders (
id integer,
firstname varchar(200),
lastname varchar(200),
email varchar(200),
paystatus varchar(1) default 'n'
);
create function checkordermail() returns trigger as '
DECLARE
customerRec RECORD;
textMessage text;
BEGIN
select into customerRec * from orders where id = NEW.id;
if customerRec.paystatus = ''y'' then
textMessage := ''Thank you for paying your bill. How sweet of you.
I love cake. Dont you?'';
perform pgmail(''Order System<os@store.com>'',customerRec.email,''You paid. How nice.'', textMessage);
end if;
return NEW;
END;' language 'plpgsql';
CREATE TRIGGER trgCheckOrderMail
AFTER INSERT OR UPDATE ON orders FOR EACH ROW
EXECUTE PROCEDURE checkordermail();