[PATCH] Fix trigger argument propagation to child partitions

From: Patrick McHardy <kaber(at)trash(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: alvherre(at)alvh(dot)no-ip(dot)org
Subject: [PATCH] Fix trigger argument propagation to child partitions
Date: 2019-07-09 13:00:27
Message-ID: 20190709130027.amr2cavjvo7rdvac@access1.trash.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The following patch fixes propagation of arguments to the trigger
function to child partitions both when initially creating the trigger
and when adding new partitions to a partitioned table.

The included regression test should demonstrate the problem, for clarity
repeated in slightly more readable form here:

bb=> create table parted_trig (a int) partition by list (a);
CREATE TABLE
bb=> create table parted_trig1 partition of parted_trig for values in (1);
CREATE TABLE
bb=> create or replace function trigger_notice() returns trigger as $$
bb$> declare
bb$> arg1 text = TG_ARGV[0];
bb$> arg2 integer = TG_ARGV[1];
bb$> begin
bb$> raise notice 'trigger % on % % % for % args % %', TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, arg1, arg2;
bb$> return null;
bb$> end;
bb$> $$ language plpgsql;
CREATE FUNCTION
bb=> create trigger aaa after insert on parted_trig for each row execute procedure trigger_notice('text', 1);
CREATE TRIGGER
bb=> \d parted_trig
Tabelle »public.parted_trig«
Spalte | Typ | Sortierfolge | NULL erlaubt? | Vorgabewert
--------+---------+--------------+---------------+-------------
a | integer | | |
Partitionsschlüssel: LIST (a)
Trigger:
aaa AFTER INSERT ON parted_trig FOR EACH ROW EXECUTE PROCEDURE trigger_notice('text', '1')
Anzahl Partitionen: 1 (Mit \d+ alle anzeigen.)

bb=> \d parted_trig1
Tabelle »public.parted_trig1«
Spalte | Typ | Sortierfolge | NULL erlaubt? | Vorgabewert
--------+---------+--------------+---------------+-------------
a | integer | | |
Partition von: parted_trig FOR VALUES IN (1)
Trigger:
aaa AFTER INSERT ON parted_trig1 FOR EACH ROW EXECUTE PROCEDURE trigger_notice()

Fixed:

bb=> \d parted_trig1
Tabelle »public.parted_trig1«
Spalte | Typ | Sortierfolge | NULL erlaubt? | Vorgabewert
--------+---------+--------------+---------------+-------------
a | integer | | |
Partition von: parted_trig FOR VALUES IN (1)
Trigger:
aaa AFTER INSERT ON parted_trig1 FOR EACH ROW EXECUTE PROCEDURE trigger_notice('text', '1')

Patch is against 11.4, but applies to master with minor offset.

All regression test pass.

Attachment Content-Type Size
v1.patch text/x-diff 5.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ryan Lambert 2019-07-09 13:13:10 Re: FETCH FIRST clause PERCENT option
Previous Message Julien Rouhaud 2019-07-09 12:56:37 Re: Add parallelism and glibc dependent only options to reindexdb