v1-0001-fix-new-collist-validation-msg.patch

application/octet-stream

Filename: v1-0001-fix-new-collist-validation-msg.patch
Type: application/octet-stream
Part: 0
Message: Re: BUG #18558: ALTER PUBLICATION fails with unhelpful error on attempt to use system column

Patch

Format: format-patch
Series: patch v1-0001
Subject: fix-new-collist-validation-msg
File+
src/backend/catalog/pg_publication.c 1 4
src/backend/commands/publicationcmds.c 6 0
src/include/catalog/pg_publication.h 2 0
From f36c484e8e76879dbe3d51c318d30d9646da4602 Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Mon, 29 Jul 2024 11:45:51 +1000
Subject: [PATCH v1] fix-new-collist-validation-msg

---
 src/backend/catalog/pg_publication.c   | 5 +----
 src/backend/commands/publicationcmds.c | 6 ++++++
 src/include/catalog/pg_publication.h   | 2 ++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 0602398..1d45572 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -48,9 +48,6 @@ typedef struct
 								 * table. */
 } published_rel;
 
-static void publication_translate_columns(Relation targetrel, List *columns,
-										  int *natts, AttrNumber **attrs);
-
 /*
  * Check if relation can be in given publication and throws appropriate
  * error if not.
@@ -498,7 +495,7 @@ compare_int16(const void *a, const void *b)
  * FirstLowInvalidHeapAttributeNumber; system columns are forbidden so this
  * is okay.
  */
-static void
+void
 publication_translate_columns(Relation targetrel, List *columns,
 							  int *natts, AttrNumber **attrs)
 {
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index 6ea7099..16a6766 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -1181,8 +1181,14 @@ AlterPublicationTables(AlterPublicationStmt *stmt, HeapTuple tup,
 				 */
 				if (newpubrel->columns)
 				{
+					AttrNumber *attarray = NULL;
+					int			natts = 0;
 					ListCell   *lc;
 
+					/* Do pre-validation of the new columns. */
+					publication_translate_columns(newpubrel->relation, newpubrel->columns,
+												  &natts, &attarray);
+
 					foreach(lc, newpubrel->columns)
 					{
 						char	   *colname = strVal(lfirst(lc));
diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/pg_publication.h
index 2f1b6ab..596f2cc 100644
--- a/src/include/catalog/pg_publication.h
+++ b/src/include/catalog/pg_publication.h
@@ -157,5 +157,7 @@ extern ObjectAddress publication_add_schema(Oid pubid, Oid schemaid,
 
 extern Bitmapset *pub_collist_to_bitmapset(Bitmapset *columns, Datum pubcols,
 										   MemoryContext mcxt);
+extern void publication_translate_columns(Relation targetrel, List *columns,
+										  int *natts, AttrNumber **attrs);
 
 #endif							/* PG_PUBLICATION_H */
-- 
1.8.3.1