@@ -1958,10 +1958,6 @@ drop table my_table;
19581958create table parted_trig (a int) partition by list (a);
19591959create function trigger_nothing() returns trigger
19601960 language plpgsql as $$ begin end; $$;
1961- create trigger failed before insert or update or delete on parted_trig
1962- for each row execute procedure trigger_nothing();
1963- ERROR: "parted_trig" is a partitioned table
1964- DETAIL: Partitioned tables cannot have BEFORE / FOR EACH ROW triggers.
19651961create trigger failed instead of update on parted_trig
19661962 for each row execute procedure trigger_nothing();
19671963ERROR: "parted_trig" is a table
@@ -2246,6 +2242,80 @@ NOTICE: aasvogel <- woof!
22462242NOTICE: trigger parted_trig on parted1_irreg AFTER INSERT for ROW: (a,b)=(3,aasvogel)
22472243NOTICE: trigger parted_trig_odd on parted1_irreg AFTER INSERT for ROW: (a,b)=(3,aasvogel)
22482244drop table parted_irreg_ancestor;
2245+ -- Before triggers and partitions
2246+ create table parted (a int, b int, c text) partition by list (a);
2247+ create table parted_1 partition of parted for values in (1)
2248+ partition by list (b);
2249+ create table parted_1_1 partition of parted_1 for values in (1);
2250+ create function parted_trigfunc() returns trigger language plpgsql as $$
2251+ begin
2252+ new.a = new.a + 1;
2253+ return new;
2254+ end;
2255+ $$;
2256+ insert into parted values (1, 1, 'uno uno v1'); -- works
2257+ create trigger t before insert or update or delete on parted
2258+ for each row execute function parted_trigfunc();
2259+ insert into parted values (1, 1, 'uno uno v2'); -- fail
2260+ ERROR: moving row to another partition during a BEFORE FOR EACH ROW trigger is not supported
2261+ DETAIL: Before executing trigger "t", the row was to be in partition "public.parted_1_1".
2262+ update parted set c = c || 'v3'; -- fail
2263+ ERROR: moving row to another partition during a BEFORE trigger is not supported
2264+ DETAIL: Before executing trigger "t", the row was to be in partition "public.parted_1_1".
2265+ create or replace function parted_trigfunc() returns trigger language plpgsql as $$
2266+ begin
2267+ new.b = new.b + 1;
2268+ return new;
2269+ end;
2270+ $$;
2271+ insert into parted values (1, 1, 'uno uno v4'); -- fail
2272+ ERROR: moving row to another partition during a BEFORE FOR EACH ROW trigger is not supported
2273+ DETAIL: Before executing trigger "t", the row was to be in partition "public.parted_1_1".
2274+ update parted set c = c || 'v5'; -- fail
2275+ ERROR: moving row to another partition during a BEFORE trigger is not supported
2276+ DETAIL: Before executing trigger "t", the row was to be in partition "public.parted_1_1".
2277+ create or replace function parted_trigfunc() returns trigger language plpgsql as $$
2278+ begin
2279+ new.c = new.c || ' and so';
2280+ return new;
2281+ end;
2282+ $$;
2283+ insert into parted values (1, 1, 'uno uno'); -- works
2284+ update parted set c = c || ' v6'; -- works
2285+ select tableoid::regclass, * from parted;
2286+ tableoid | a | b | c
2287+ ------------+---+---+--------------------------
2288+ parted_1_1 | 1 | 1 | uno uno v1 v6 and so
2289+ parted_1_1 | 1 | 1 | uno uno and so v6 and so
2290+ (2 rows)
2291+
2292+ drop table parted;
2293+ create table parted (a int, b int, c text) partition by list ((a + b));
2294+ create or replace function parted_trigfunc() returns trigger language plpgsql as $$
2295+ begin
2296+ new.a = new.a + new.b;
2297+ return new;
2298+ end;
2299+ $$;
2300+ create table parted_1 partition of parted for values in (1, 2);
2301+ create table parted_2 partition of parted for values in (3, 4);
2302+ create trigger t before insert or update on parted
2303+ for each row execute function parted_trigfunc();
2304+ insert into parted values (0, 1, 'zero win');
2305+ insert into parted values (1, 1, 'one fail');
2306+ ERROR: moving row to another partition during a BEFORE FOR EACH ROW trigger is not supported
2307+ DETAIL: Before executing trigger "t", the row was to be in partition "public.parted_1".
2308+ insert into parted values (1, 2, 'two fail');
2309+ ERROR: moving row to another partition during a BEFORE FOR EACH ROW trigger is not supported
2310+ DETAIL: Before executing trigger "t", the row was to be in partition "public.parted_2".
2311+ select * from parted;
2312+ a | b | c
2313+ ---+---+----------
2314+ 1 | 1 | zero win
2315+ (1 row)
2316+
2317+ drop table parted;
2318+ drop function parted_trigfunc();
22492319--
22502320-- Constraint triggers and partitioned tables
22512321create table parted_constr_ancestor (a int, b text)
0 commit comments