Skip to content

Commit 8cc157b

Browse files
committed
Fix ALTER TRIGGER ... RENAME, broken in WITH OIDS removal.
I (Andres) broke this in 578b229. Author: Rushabh Lathia Discussion: https://postgr.es/m/CAGPqQf04PywZX3sVQaF6H=oLiW9GJncRW+=e78vTy4MokEWcZw@mail.gmail.com
1 parent 93507e6 commit 8cc157b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/backend/commands/trigger.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,14 +1721,14 @@ renametrig(RenameStmt *stmt)
17211721
NULL, 2, key);
17221722
if (HeapTupleIsValid(tuple = systable_getnext(tgscan)))
17231723
{
1724-
Form_pg_trigger trigform = (Form_pg_trigger) GETSTRUCT(tuple);
1725-
1726-
tgoid = trigform->oid;
1724+
Form_pg_trigger trigform;
17271725

17281726
/*
17291727
* Update pg_trigger tuple with new tgname.
17301728
*/
17311729
tuple = heap_copytuple(tuple); /* need a modifiable copy */
1730+
trigform = (Form_pg_trigger) GETSTRUCT(tuple);
1731+
tgoid = trigform->oid;
17321732

17331733
namestrcpy(&trigform->tgname,
17341734
stmt->newname);

src/test/regress/expected/triggers.out

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,21 @@ SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'
434434
CREATE TRIGGER modified_any BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.* IS DISTINCT FROM new.*) EXECUTE PROCEDURE trigger_func('modified_any')
435435
(1 row)
436436

437-
DROP TRIGGER modified_a ON main_table;
437+
-- Test RENAME TRIGGER
438+
ALTER TRIGGER modified_a ON main_table RENAME TO modified_modified_a;
439+
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
440+
count
441+
-------
442+
0
443+
(1 row)
444+
445+
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_modified_a';
446+
count
447+
-------
448+
1
449+
(1 row)
450+
451+
DROP TRIGGER modified_modified_a ON main_table;
438452
DROP TRIGGER modified_any ON main_table;
439453
DROP TRIGGER insert_a ON main_table;
440454
DROP TRIGGER delete_a ON main_table;

src/test/regress/sql/triggers.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,13 @@ SELECT * FROM main_table ORDER BY a, b;
284284
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
285285
SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
286286
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any';
287-
DROP TRIGGER modified_a ON main_table;
287+
288+
-- Test RENAME TRIGGER
289+
ALTER TRIGGER modified_a ON main_table RENAME TO modified_modified_a;
290+
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
291+
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_modified_a';
292+
293+
DROP TRIGGER modified_modified_a ON main_table;
288294
DROP TRIGGER modified_any ON main_table;
289295
DROP TRIGGER insert_a ON main_table;
290296
DROP TRIGGER delete_a ON main_table;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy