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
|
\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;
WARNING: insert_event(q=[jsontriga], t=[{"op":"TRUNCATE","table":["public","jsontriga_trunc"],"pkey":["dat1"]}], d=[{}], 1=[public.jsontriga_trunc], 2=[<NULL>], 3=[<NULL>], 4=[<NULL>])
truncate logutriga_trunc;
WARNING: insert_event(q=[logutriga], t=[R], d=[], 1=[public.logutriga_trunc], 2=[<NULL>], 3=[<NULL>], 4=[<NULL>])
truncate sqltriga_trunc;
WARNING: insert_event(q=[sqltriga], t=[R], d=[], 1=[public.sqltriga_trunc], 2=[<NULL>], 3=[<NULL>], 4=[<NULL>])
-- 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;
ERROR: Table 'public.jsontriga_trunc2' to queue 'jsontriga_trunc2': change not allowed (TRUNCATE)
truncate logutriga_trunc2;
ERROR: Table 'public.logutriga_trunc2' to queue 'logutriga_trunc2': change not allowed (TRUNCATE)
truncate sqltriga_trunc2;
ERROR: Table 'public.sqltriga_trunc2' to queue 'sqltriga_trunc2': change not allowed (TRUNCATE)
-- 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
|