File: trigger_extra_args.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 (41 lines) | stat: -rw-r--r-- 1,632 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
\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 trigger_extra_args (nr int4 primary key, col1 text, col2 text);

create trigger extra_trig_0 after insert or update or delete on trigger_extra_args
for each row execute procedure pgq.jsontriga('jsontriga',
    'ev_extra1=(nr+3)::text', 'ev_extra2=col1||col2',
    'ev_extra3=$$333$$', 'ev_extra4=$$444$$', 'ev_type=$$badidea$$');
create trigger extra_trig_1 after insert or update or delete on trigger_extra_args
for each row execute procedure pgq.logutriga('logutriga',
    'ev_extra1=(nr+3)::text', 'ev_extra2=col1||col2',
    'ev_extra3=$$333$$', 'ev_extra4=$$444$$', 'ev_type=$$badidea$$');
create trigger extra_trig_2 after insert or update or delete on trigger_extra_args
for each row execute procedure pgq.sqltriga('sqltriga',
    'ev_extra1=(nr+3)::text', 'ev_extra2=col1||col2',
    'ev_extra3=$$333$$', 'ev_extra4=$$444$$', 'ev_type=$$badidea$$');

-- test insert
insert into trigger_extra_args values (1, 'col1', 'col2');

-- test update
update trigger_extra_args set col1 = 'col1x', col2='col2x' where nr=1;

-- test delete
delete from trigger_extra_args where nr=1;

-- restore
drop table trigger_extra_args;
\set ECHO none
\i functions/pgq.insert_event.sql