Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f3c4537

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 ec5bab9 commit f3c4537

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5084,19 +5084,18 @@ getObjectIdentityParts(const ObjectAddress *object,
50845084
{
50855085
HeapTuple tup;
50865086
Form_pg_event_trigger trigForm;
5087-
5088-
/* no objname support here */
5089-
if (objname)
5090-
*objname = NIL;
5087+
char *evtname;
50915088

50925089
tup = SearchSysCache1(EVENTTRIGGEROID,
50935090
ObjectIdGetDatum(object->objectId));
50945091
if (!HeapTupleIsValid(tup))
50955092
elog(ERROR, "cache lookup failed for event trigger %u",
50965093
object->objectId);
50975094
trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5098-
appendStringInfoString(&buffer,
5099-
quote_identifier(NameStr(trigForm->evtname)));
5095+
evtname = NameStr(trigForm->evtname);
5096+
appendStringInfoString(&buffer, quote_identifier(evtname));
5097+
if (objname)
5098+
*objname = list_make1(evtname);
51005099
ReleaseSysCache(tup);
51015100
break;
51025101
}

src/test/regress/expected/event_trigger.out

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,23 @@ DROP POLICY p2 ON event_trigger_test;
533533
NOTICE: DROP POLICY - ddl_command_start
534534
NOTICE: DROP POLICY - sql_drop
535535
NOTICE: DROP POLICY - ddl_command_end
536+
-- Check the object addresses of all the event triggers.
537+
SELECT
538+
e.evtname,
539+
pg_describe_object('pg_event_trigger'::regclass, e.oid, 0) as descr,
540+
b.type, b.object_names, b.object_args,
541+
pg_identify_object(a.classid, a.objid, a.objsubid) as ident
542+
FROM pg_event_trigger as e,
543+
LATERAL pg_identify_object_as_address('pg_event_trigger'::regclass, e.oid, 0) as b,
544+
LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a
545+
ORDER BY e.evtname;
546+
evtname | descr | type | object_names | object_args | ident
547+
-------------------+---------------------------------+---------------+---------------------+-------------+--------------------------------------------------------
548+
end_rls_command | event trigger end_rls_command | event trigger | {end_rls_command} | {} | ("event trigger",,end_rls_command,end_rls_command)
549+
sql_drop_command | event trigger sql_drop_command | event trigger | {sql_drop_command} | {} | ("event trigger",,sql_drop_command,sql_drop_command)
550+
start_rls_command | event trigger start_rls_command | event trigger | {start_rls_command} | {} | ("event trigger",,start_rls_command,start_rls_command)
551+
(3 rows)
552+
536553
DROP EVENT TRIGGER start_rls_command;
537554
DROP EVENT TRIGGER end_rls_command;
538555
DROP EVENT TRIGGER sql_drop_command;

src/test/regress/sql/event_trigger.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,17 @@ ALTER POLICY p1 ON event_trigger_test USING (TRUE);
426426
ALTER POLICY p1 ON event_trigger_test RENAME TO p2;
427427
DROP POLICY p2 ON event_trigger_test;
428428

429+
-- Check the object addresses of all the event triggers.
430+
SELECT
431+
e.evtname,
432+
pg_describe_object('pg_event_trigger'::regclass, e.oid, 0) as descr,
433+
b.type, b.object_names, b.object_args,
434+
pg_identify_object(a.classid, a.objid, a.objsubid) as ident
435+
FROM pg_event_trigger as e,
436+
LATERAL pg_identify_object_as_address('pg_event_trigger'::regclass, e.oid, 0) as b,
437+
LATERAL pg_get_object_address(b.type, b.object_names, b.object_args) as a
438+
ORDER BY e.evtname;
439+
429440
DROP EVENT TRIGGER start_rls_command;
430441
DROP EVENT TRIGGER end_rls_command;
431442
DROP EVENT TRIGGER sql_drop_command;

0 commit comments

Comments
 (0)