Skip to content

Commit 6e41ff0

Browse files
committed
Fix pg_identify_object_as_address() with event triggers
Attempting to use this function with event triggers failed, as, since its introduction in a676201, this code has never associated an object name with event triggers. This addresses the failure by adding the event trigger name to the set defining its object address. Note that regression tests are added within event_trigger and not object_address to avoid issues with concurrent connections in parallel schedules. Author: Joel Jacobson Discussion: https://postgr.es/m/3c905e77-a026-46ae-8835-c3f6cd1d24c8@www.fastmail.com Backpatch-through: 9.6
1 parent b391db4 commit 6e41ff0

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/backend/catalog/objectaddress.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -4673,19 +4673,18 @@ getObjectIdentityParts(const ObjectAddress *object,
46734673
{
46744674
HeapTuple tup;
46754675
Form_pg_event_trigger trigForm;
4676-
4677-
/* no objname support here */
4678-
if (objname)
4679-
*objname = NIL;
4676+
char *evtname;
46804677

46814678
tup = SearchSysCache1(EVENTTRIGGEROID,
46824679
ObjectIdGetDatum(object->objectId));
46834680
if (!HeapTupleIsValid(tup))
46844681
elog(ERROR, "cache lookup failed for event trigger %u",
46854682
object->objectId);
46864683
trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
4687-
appendStringInfoString(&buffer,
4688-
quote_identifier(NameStr(trigForm->evtname)));
4684+
evtname = NameStr(trigForm->evtname);
4685+
appendStringInfoString(&buffer, quote_identifier(evtname));
4686+
if (objname)
4687+
*objname = list_make1(evtname);
46894688
ReleaseSysCache(tup);
46904689
break;
46914690
}

src/test/regress/expected/event_trigger.out

+15
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,21 @@ DROP POLICY p2 ON event_trigger_test;
458458
NOTICE: DROP POLICY - ddl_command_start
459459
NOTICE: DROP POLICY - sql_drop
460460
NOTICE: DROP POLICY - ddl_command_end
461+
-- Check the object addresses of all the event triggers.
462+
SELECT
463+
evtname,
464+
pg_describe_object('pg_event_trigger'::regclass, oid, 0),
465+
pg_identify_object('pg_event_trigger'::regclass, oid, 0),
466+
pg_identify_object_as_address('pg_event_trigger'::regclass, oid, 0)
467+
FROM pg_event_trigger
468+
ORDER BY evtname;
469+
evtname | pg_describe_object | pg_identify_object | pg_identify_object_as_address
470+
-------------------+---------------------------------+--------------------------------------------------------+------------------------------------------
471+
end_rls_command | event trigger end_rls_command | ("event trigger",,end_rls_command,end_rls_command) | ("event trigger",{end_rls_command},{})
472+
sql_drop_command | event trigger sql_drop_command | ("event trigger",,sql_drop_command,sql_drop_command) | ("event trigger",{sql_drop_command},{})
473+
start_rls_command | event trigger start_rls_command | ("event trigger",,start_rls_command,start_rls_command) | ("event trigger",{start_rls_command},{})
474+
(3 rows)
475+
461476
DROP EVENT TRIGGER start_rls_command;
462477
DROP EVENT TRIGGER end_rls_command;
463478
DROP EVENT TRIGGER sql_drop_command;

src/test/regress/sql/event_trigger.sql

+9
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ ALTER POLICY p1 ON event_trigger_test USING (TRUE);
378378
ALTER POLICY p1 ON event_trigger_test RENAME TO p2;
379379
DROP POLICY p2 ON event_trigger_test;
380380

381+
-- Check the object addresses of all the event triggers.
382+
SELECT
383+
evtname,
384+
pg_describe_object('pg_event_trigger'::regclass, oid, 0),
385+
pg_identify_object('pg_event_trigger'::regclass, oid, 0),
386+
pg_identify_object_as_address('pg_event_trigger'::regclass, oid, 0)
387+
FROM pg_event_trigger
388+
ORDER BY evtname;
389+
381390
DROP EVENT TRIGGER start_rls_command;
382391
DROP EVENT TRIGGER end_rls_command;
383392
DROP EVENT TRIGGER sql_drop_command;

0 commit comments

Comments
 (0)