Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa51cc8

Browse files
committed
Backpatch regression tests added by 2d689ba
A new plpgsql test function was added in 14 and up to cover for a bugfix that was not backpatchable. We can add it to older versions as a way to cover other bits of DDL event triggers, with an exception clause to avoid the problematic corner case. Originally authored by Michaël Paquier. Backpatch: 10 through 13. Discussion: https://postgr.es/m/[email protected]
1 parent b57e30c commit fa51cc8

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

src/test/regress/expected/event_trigger.out

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ SELECT * FROM dropped_objects WHERE type = 'schema';
313313
DROP ROLE regress_evt_user;
314314
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
315315
DROP EVENT TRIGGER undroppable;
316+
-- Event triggers on relations.
316317
CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
317318
RETURNS event_trigger
318319
LANGUAGE plpgsql
@@ -331,41 +332,91 @@ BEGIN
331332
END; $$;
332333
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
333334
EXECUTE PROCEDURE event_trigger_report_dropped();
335+
CREATE OR REPLACE FUNCTION event_trigger_report_end()
336+
RETURNS event_trigger
337+
LANGUAGE plpgsql
338+
AS $$
339+
DECLARE r RECORD;
340+
BEGIN
341+
FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
342+
LOOP
343+
RAISE NOTICE 'END: command_tag=% type=% identity=%',
344+
r.command_tag, r.object_type, r.object_identity;
345+
END LOOP;
346+
EXCEPTION WHEN SQLSTATE 'XX000' THEN
347+
RAISE NOTICE 'END: got internal exception';
348+
END; $$;
349+
CREATE EVENT TRIGGER regress_event_trigger_report_end ON ddl_command_end
350+
EXECUTE PROCEDURE event_trigger_report_end();
334351
CREATE SCHEMA evttrig
335-
CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
352+
CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two', col_c SERIAL)
336353
CREATE INDEX one_idx ON one (col_b)
337-
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
354+
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42)
355+
CREATE TABLE id (col_d int NOT NULL GENERATED ALWAYS AS IDENTITY);
356+
NOTICE: END: command_tag=CREATE SCHEMA type=schema identity=evttrig
357+
NOTICE: END: command_tag=CREATE SEQUENCE type=sequence identity=evttrig.one_col_a_seq
358+
NOTICE: END: command_tag=CREATE SEQUENCE type=sequence identity=evttrig.one_col_c_seq
359+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.one
360+
NOTICE: END: command_tag=CREATE INDEX type=index identity=evttrig.one_pkey
361+
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.one_col_a_seq
362+
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.one_col_c_seq
363+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.two
364+
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.two
365+
NOTICE: END: command_tag=CREATE SEQUENCE type=sequence identity=evttrig.id_col_d_seq
366+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.id
367+
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.id_col_d_seq
368+
NOTICE: END: command_tag=CREATE INDEX type=index identity=evttrig.one_idx
338369
-- Partitioned tables
339370
CREATE TABLE evttrig.parted (
340371
id int)
341372
PARTITION BY RANGE (id);
373+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.parted
342374
CREATE TABLE evttrig.part_1_10 PARTITION OF evttrig.parted (id)
343375
FOR VALUES FROM (1) TO (10);
376+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_1_10
344377
CREATE TABLE evttrig.part_10_20 PARTITION OF evttrig.parted (id)
345378
FOR VALUES FROM (10) TO (20) PARTITION BY RANGE (id);
379+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_10_20
346380
CREATE TABLE evttrig.part_10_15 PARTITION OF evttrig.part_10_20 (id)
347381
FOR VALUES FROM (10) TO (15);
382+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_10_15
348383
CREATE TABLE evttrig.part_15_20 PARTITION OF evttrig.part_10_20 (id)
349384
FOR VALUES FROM (15) TO (20);
385+
NOTICE: END: command_tag=CREATE TABLE type=table identity=evttrig.part_15_20
350386
ALTER TABLE evttrig.two DROP COLUMN col_c;
351387
NOTICE: NORMAL: orig=t normal=f istemp=f type=table column identity=evttrig.two.col_c name={evttrig,two,col_c} args={}
352388
NOTICE: NORMAL: orig=f normal=t istemp=f type=table constraint identity=two_col_c_check on evttrig.two name={evttrig,two,two_col_c_check} args={}
389+
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.two
353390
ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
354391
NOTICE: NORMAL: orig=t normal=f istemp=f type=default value identity=for evttrig.one.col_b name={evttrig,one,col_b} args={}
392+
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
355393
ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
356394
NOTICE: NORMAL: orig=t normal=f istemp=f type=table constraint identity=one_pkey on evttrig.one name={evttrig,one,one_pkey} args={}
395+
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
396+
ALTER TABLE evttrig.one DROP COLUMN col_c;
397+
NOTICE: NORMAL: orig=t normal=f istemp=f type=table column identity=evttrig.one.col_c name={evttrig,one,col_c} args={}
398+
NOTICE: NORMAL: orig=f normal=t istemp=f type=default value identity=for evttrig.one.col_c name={evttrig,one,col_c} args={}
399+
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.one
400+
ALTER TABLE evttrig.id ALTER COLUMN col_d SET DATA TYPE bigint;
401+
NOTICE: END: command_tag=ALTER SEQUENCE type=sequence identity=evttrig.id_col_d_seq
402+
NOTICE: END: command_tag=ALTER TABLE type=table identity=evttrig.id
403+
ALTER TABLE evttrig.id ALTER COLUMN col_d DROP IDENTITY,
404+
ALTER COLUMN col_d SET DATA TYPE int;
405+
NOTICE: END: got internal exception
357406
DROP INDEX evttrig.one_idx;
358407
NOTICE: NORMAL: orig=t normal=f istemp=f type=index identity=evttrig.one_idx name={evttrig,one_idx} args={}
359408
DROP SCHEMA evttrig CASCADE;
360-
NOTICE: drop cascades to 3 other objects
409+
NOTICE: drop cascades to 4 other objects
361410
DETAIL: drop cascades to table evttrig.one
362411
drop cascades to table evttrig.two
412+
drop cascades to table evttrig.id
363413
drop cascades to table evttrig.parted
364414
NOTICE: NORMAL: orig=t normal=f istemp=f type=schema identity=evttrig name={evttrig} args={}
365415
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.one name={evttrig,one} args={}
366416
NOTICE: NORMAL: orig=f normal=t istemp=f type=sequence identity=evttrig.one_col_a_seq name={evttrig,one_col_a_seq} args={}
367417
NOTICE: NORMAL: orig=f normal=t istemp=f type=default value identity=for evttrig.one.col_a name={evttrig,one,col_a} args={}
368418
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.two name={evttrig,two} args={}
419+
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.id name={evttrig,id} args={}
369420
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.parted name={evttrig,parted} args={}
370421
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_1_10 name={evttrig,part_1_10} args={}
371422
NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_10_20 name={evttrig,part_10_20} args={}
@@ -374,6 +425,7 @@ NOTICE: NORMAL: orig=f normal=t istemp=f type=table identity=evttrig.part_15_20
374425
DROP TABLE a_temp_tbl;
375426
NOTICE: NORMAL: orig=t normal=f istemp=t type=table identity=pg_temp.a_temp_tbl name={pg_temp,a_temp_tbl} args={}
376427
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
428+
DROP EVENT TRIGGER regress_event_trigger_report_end;
377429
-- only allowed from within an event trigger function, should fail
378430
select pg_event_trigger_table_rewrite_oid();
379431
ERROR: pg_event_trigger_table_rewrite_oid() can only be called in a table_rewrite event trigger function

src/test/regress/sql/event_trigger.sql

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ DROP ROLE regress_evt_user;
243243
DROP EVENT TRIGGER regress_event_trigger_drop_objects;
244244
DROP EVENT TRIGGER undroppable;
245245

246+
-- Event triggers on relations.
246247
CREATE OR REPLACE FUNCTION event_trigger_report_dropped()
247248
RETURNS event_trigger
248249
LANGUAGE plpgsql
@@ -261,10 +262,28 @@ BEGIN
261262
END; $$;
262263
CREATE EVENT TRIGGER regress_event_trigger_report_dropped ON sql_drop
263264
EXECUTE PROCEDURE event_trigger_report_dropped();
265+
CREATE OR REPLACE FUNCTION event_trigger_report_end()
266+
RETURNS event_trigger
267+
LANGUAGE plpgsql
268+
AS $$
269+
DECLARE r RECORD;
270+
BEGIN
271+
FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
272+
LOOP
273+
RAISE NOTICE 'END: command_tag=% type=% identity=%',
274+
r.command_tag, r.object_type, r.object_identity;
275+
END LOOP;
276+
EXCEPTION WHEN SQLSTATE 'XX000' THEN
277+
RAISE NOTICE 'END: got internal exception';
278+
END; $$;
279+
CREATE EVENT TRIGGER regress_event_trigger_report_end ON ddl_command_end
280+
EXECUTE PROCEDURE event_trigger_report_end();
281+
264282
CREATE SCHEMA evttrig
265-
CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two')
283+
CREATE TABLE one (col_a SERIAL PRIMARY KEY, col_b text DEFAULT 'forty two', col_c SERIAL)
266284
CREATE INDEX one_idx ON one (col_b)
267-
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42);
285+
CREATE TABLE two (col_c INTEGER CHECK (col_c > 0) REFERENCES one DEFAULT 42)
286+
CREATE TABLE id (col_d int NOT NULL GENERATED ALWAYS AS IDENTITY);
268287

269288
-- Partitioned tables
270289
CREATE TABLE evttrig.parted (
@@ -282,11 +301,16 @@ CREATE TABLE evttrig.part_15_20 PARTITION OF evttrig.part_10_20 (id)
282301
ALTER TABLE evttrig.two DROP COLUMN col_c;
283302
ALTER TABLE evttrig.one ALTER COLUMN col_b DROP DEFAULT;
284303
ALTER TABLE evttrig.one DROP CONSTRAINT one_pkey;
304+
ALTER TABLE evttrig.one DROP COLUMN col_c;
305+
ALTER TABLE evttrig.id ALTER COLUMN col_d SET DATA TYPE bigint;
306+
ALTER TABLE evttrig.id ALTER COLUMN col_d DROP IDENTITY,
307+
ALTER COLUMN col_d SET DATA TYPE int;
285308
DROP INDEX evttrig.one_idx;
286309
DROP SCHEMA evttrig CASCADE;
287310
DROP TABLE a_temp_tbl;
288311

289312
DROP EVENT TRIGGER regress_event_trigger_report_dropped;
313+
DROP EVENT TRIGGER regress_event_trigger_report_end;
290314

291315
-- only allowed from within an event trigger function, should fail
292316
select pg_event_trigger_table_rewrite_oid();

0 commit comments

Comments
 (0)