Commit 8cc157b2 authored by Andres Freund's avatar Andres Freund

Fix ALTER TRIGGER ... RENAME, broken in WITH OIDS removal.

I (Andres) broke this in 578b2297.

Author: Rushabh Lathia
Discussion: https://postgr.es/m/CAGPqQf04PywZX3sVQaF6H=oLiW9GJncRW+=e78vTy4MokEWcZw@mail.gmail.com
parent 93507e67
...@@ -1721,14 +1721,14 @@ renametrig(RenameStmt *stmt) ...@@ -1721,14 +1721,14 @@ renametrig(RenameStmt *stmt)
NULL, 2, key); NULL, 2, key);
if (HeapTupleIsValid(tuple = systable_getnext(tgscan))) if (HeapTupleIsValid(tuple = systable_getnext(tgscan)))
{ {
Form_pg_trigger trigform = (Form_pg_trigger) GETSTRUCT(tuple); Form_pg_trigger trigform;
tgoid = trigform->oid;
/* /*
* Update pg_trigger tuple with new tgname. * Update pg_trigger tuple with new tgname.
*/ */
tuple = heap_copytuple(tuple); /* need a modifiable copy */ tuple = heap_copytuple(tuple); /* need a modifiable copy */
trigform = (Form_pg_trigger) GETSTRUCT(tuple);
tgoid = trigform->oid;
namestrcpy(&trigform->tgname, namestrcpy(&trigform->tgname,
stmt->newname); stmt->newname);
......
...@@ -434,7 +434,21 @@ SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table' ...@@ -434,7 +434,21 @@ SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'
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') 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')
(1 row) (1 row)
DROP TRIGGER modified_a ON main_table; -- Test RENAME TRIGGER
ALTER TRIGGER modified_a ON main_table RENAME TO modified_modified_a;
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
count
-------
0
(1 row)
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_modified_a';
count
-------
1
(1 row)
DROP TRIGGER modified_modified_a ON main_table;
DROP TRIGGER modified_any ON main_table; DROP TRIGGER modified_any ON main_table;
DROP TRIGGER insert_a ON main_table; DROP TRIGGER insert_a ON main_table;
DROP TRIGGER delete_a ON main_table; DROP TRIGGER delete_a ON main_table;
......
...@@ -284,7 +284,13 @@ SELECT * FROM main_table ORDER BY a, b; ...@@ -284,7 +284,13 @@ SELECT * FROM main_table ORDER BY a, b;
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a'; SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a'; SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any'; SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any';
DROP TRIGGER modified_a ON main_table;
-- Test RENAME TRIGGER
ALTER TRIGGER modified_a ON main_table RENAME TO modified_modified_a;
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
SELECT count(*) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_modified_a';
DROP TRIGGER modified_modified_a ON main_table;
DROP TRIGGER modified_any ON main_table; DROP TRIGGER modified_any ON main_table;
DROP TRIGGER insert_a ON main_table; DROP TRIGGER insert_a ON main_table;
DROP TRIGGER delete_a ON main_table; DROP TRIGGER delete_a ON main_table;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment