File: trigger_base.sql

package info (click to toggle)
pgq 3.2.6-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 836 kB
  • sloc: sql: 3,412; ansic: 1,990; python: 302; makefile: 89; sh: 2
file content (83 lines) | stat: -rw-r--r-- 3,344 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
\set VERBOSITY 'terse'
set client_min_messages = 'warning';
set bytea_output = 'hex';

create or replace function pgq.insert_event(queue_name text, ev_type text, ev_data text, ev_extra1 text, ev_extra2 text, ev_extra3 text, ev_extra4 text)
returns bigint as $$
begin
    raise warning 'insert_event(q=[%], t=[%], d=[%], 1=[%], 2=[%], 3=[%], 4=[%])',
        queue_name, ev_type, ev_data, ev_extra1, ev_extra2, ev_extra3, ev_extra4;
    return 1;
end;
$$ language plpgsql;

create table trigger_base (
    id serial primary key,
    txt text,
    val float
);

create trigger base_trig_0 after insert or update or delete on trigger_base
for each row execute procedure pgq.jsontriga('jsontriga');
create trigger base_trig_1 after insert or update or delete on trigger_base
for each row execute procedure pgq.logutriga('logutriga');
create trigger base_trig_2 after insert or update or delete on trigger_base
for each row execute procedure pgq.sqltriga('sqltriga');

insert into trigger_base (txt) values ('text1');
insert into trigger_base (val) values (1.5);
update trigger_base set txt='text2' where id=1;
delete from trigger_base where id=2;

-- test missing pkey
create table trigger_nopkey_jsontriga (dat text);
create table trigger_nopkey_logutriga (dat text);
create table trigger_nopkey_sqltriga (dat text);

create trigger nopkey after insert or update or delete on trigger_nopkey_jsontriga
for each row execute procedure pgq.jsontriga('jsontriga');
create trigger nopkey after insert or update or delete on trigger_nopkey_logutriga
for each row execute procedure pgq.logutriga('logutriga');
create trigger nopkey after insert or update or delete on trigger_nopkey_sqltriga
for each row execute procedure pgq.sqltriga('sqltriga');

insert into trigger_nopkey_jsontriga values ('foo');
insert into trigger_nopkey_logutriga values ('foo');
insert into trigger_nopkey_sqltriga values ('foo');
update trigger_nopkey_jsontriga set dat = 'bat';
update trigger_nopkey_logutriga set dat = 'bat';
update trigger_nopkey_sqltriga set dat = 'bat';
delete from trigger_nopkey_jsontriga;
delete from trigger_nopkey_logutriga;
delete from trigger_nopkey_sqltriga;

-- test invalid pk update
create table trigger_pkey_jsontriga (id int4 primary key);
create table trigger_pkey_logutriga (id int4 primary key);
create table trigger_pkey_sqltriga (id int4 primary key);
insert into trigger_pkey_jsontriga values (1);
insert into trigger_pkey_logutriga values (1);
insert into trigger_pkey_sqltriga values (1);
create trigger nopkey after insert or update or delete on trigger_pkey_jsontriga
for each row execute procedure pgq.jsontriga('jsontriga');
create trigger nopkey after insert or update or delete on trigger_pkey_logutriga
for each row execute procedure pgq.logutriga('logutriga');
create trigger nopkey after insert or update or delete on trigger_pkey_sqltriga
for each row execute procedure pgq.sqltriga('sqltriga');

update trigger_pkey_jsontriga set id = 6;
update trigger_pkey_logutriga set id = 6;
update trigger_pkey_sqltriga set id = 6;

-- restore
drop table trigger_base;
drop table trigger_nopkey_jsontriga;
drop table trigger_nopkey_logutriga;
drop table trigger_nopkey_sqltriga;
drop table trigger_pkey_jsontriga;
drop table trigger_pkey_logutriga;
drop table trigger_pkey_sqltriga;

\set ECHO none
\i functions/pgq.insert_event.sql