v1-0001-Fix-pg_event_trigger_ddl_commands.patch

application/x-patch

Filename: v1-0001-Fix-pg_event_trigger_ddl_commands.patch
Type: application/x-patch
Part: 0
Message: Fix dropped object handling in pg_event_trigger_ddl_commands

Patch

Format: format-patch
Series: patch v1-0001
Subject: Fix pg_event_trigger_ddl_commands
File+
src/backend/commands/event_trigger.c 11 2
From 4faf761528c735bd808e7ea4d9f356710e3a8ed0 Mon Sep 17 00:00:00 2001
From: Sven Klemm <sven@timescale.com>
Date: Sat, 17 Apr 2021 21:54:03 +0200
Subject: [PATCH v1] Fix pg_event_trigger_ddl_commands

If an object is modified that is dropped in the same
command we might end up in a position where we
generated a message but can no longer look up the
object information because the object got dropped.
E.g. ALTER TABLE ALTER COLUMN, DROP IDENTITY
---
 src/backend/commands/event_trigger.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index 5bde507c75..f7b2c30f82 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -1936,8 +1936,17 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
 					else if (cmd->type == SCT_AlterTSConfig)
 						addr = cmd->d.atscfg.address;
 
-					type = getObjectTypeDescription(&addr, false);
-					identity = getObjectIdentity(&addr, false);
+					/*
+					 * If an object is modified that is dropped in the same
+					 * command we might end up in a position where we
+					 * generated a message but can no longer look up the
+					 * object information because the object got dropped.
+					 * E.g. ALTER TABLE ALTER COLUMN, DROP IDENTITY
+					 */
+					type = getObjectTypeDescription(&addr, true);
+					identity = getObjectIdentity(&addr, true);
+					if (!identity)
+						continue;
 
 					/*
 					 * Obtain schema name, if any ("pg_temp" if a temp
-- 
2.30.0