File: trigger_trunc.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 (56 lines) | stat: -rw-r--r-- 2,002 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
\set VERBOSITY 'terse'
set client_min_messages = 'warning';

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 jsontriga_trunc (dat1 text primary key);
create table logutriga_trunc (dat1 text primary key);
create table sqltriga_trunc (dat1 text primary key);

-- test successful truncate

create trigger trunc1_trig after truncate on jsontriga_trunc
for each statement execute procedure pgq.jsontriga('jsontriga');
create trigger trunc1_trig after truncate on logutriga_trunc
for each statement execute procedure pgq.logutriga('logutriga');
create trigger trunc1_trig after truncate on sqltriga_trunc
for each statement execute procedure pgq.sqltriga('sqltriga');

truncate jsontriga_trunc;
truncate logutriga_trunc;
truncate sqltriga_trunc;

-- test deny

create table jsontriga_trunc2 (dat1 text primary key);
create table logutriga_trunc2 (dat1 text primary key);
create table sqltriga_trunc2 (dat1 text primary key);

create trigger trunc_trig after truncate on jsontriga_trunc2
for each statement execute procedure pgq.jsontriga('jsontriga_trunc2', 'deny');
create trigger trunc_trig after truncate on logutriga_trunc2
for each statement execute procedure pgq.sqltriga('logutriga_trunc2', 'deny');
create trigger trunc_trig after truncate on sqltriga_trunc2
for each statement execute procedure pgq.sqltriga('sqltriga_trunc2', 'deny');

truncate jsontriga_trunc2;
truncate logutriga_trunc2;
truncate sqltriga_trunc2;

-- restore
drop table jsontriga_trunc;
drop table logutriga_trunc;
drop table sqltriga_trunc;
drop table jsontriga_trunc2;
drop table logutriga_trunc2;
drop table sqltriga_trunc2;
\set ECHO none
\i functions/pgq.insert_event.sql