From e4e44d3e054f8b8baadc4ae86d993100f90d20af Mon Sep 17 00:00:00 2001
From: Vignesh <vignesh21@gmail.com>
Date: Thu, 16 Jan 2025 12:09:13 +0530
Subject: [PATCH v52 1/5] Fix describe publication with PG17.

When using a psql client to describe a publication on a PG17 server,
an issue occurred because the newly added column was not the last field
in the selection, resulting in an incorrect column value during result
retrieval. This was fixed by ensuring the new column is added as the
last column during select and adjusting the column value accordingly
while fetching the results.
---
 src/bin/psql/describe.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 2ef99971ac..988b96b259 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -6466,8 +6466,8 @@ describePublications(const char *pattern)
 	int			i;
 	PGresult   *res;
 	bool		has_pubtruncate;
-	bool		has_pubgencols;
 	bool		has_pubviaroot;
+	bool		has_pubgencols;
 
 	PQExpBufferData title;
 	printTableContent cont;
@@ -6483,8 +6483,8 @@ describePublications(const char *pattern)
 	}
 
 	has_pubtruncate = (pset.sversion >= 110000);
-	has_pubgencols = (pset.sversion >= 180000);
 	has_pubviaroot = (pset.sversion >= 130000);
+	has_pubgencols = (pset.sversion >= 180000);
 
 	initPQExpBuffer(&buf);
 
@@ -6495,12 +6495,12 @@ describePublications(const char *pattern)
 	if (has_pubtruncate)
 		appendPQExpBufferStr(&buf,
 							 ", pubtruncate");
-	if (has_pubgencols)
-		appendPQExpBufferStr(&buf,
-							 ", pubgencols");
 	if (has_pubviaroot)
 		appendPQExpBufferStr(&buf,
 							 ", pubviaroot");
+	if (has_pubgencols)
+		appendPQExpBufferStr(&buf,
+							 ", pubgencols");
 
 	appendPQExpBufferStr(&buf,
 						 "\nFROM pg_catalog.pg_publication\n");
@@ -6551,10 +6551,10 @@ describePublications(const char *pattern)
 
 		if (has_pubtruncate)
 			ncols++;
-		if (has_pubgencols)
-			ncols++;
 		if (has_pubviaroot)
 			ncols++;
+		if (has_pubgencols)
+			ncols++;
 
 		initPQExpBuffer(&title);
 		printfPQExpBuffer(&title, _("Publication %s"), pubname);
@@ -6580,9 +6580,9 @@ describePublications(const char *pattern)
 		if (has_pubtruncate)
 			printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
 		if (has_pubgencols)
-			printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
-		if (has_pubviaroot)
 			printTableAddCell(&cont, PQgetvalue(res, i, 9), false, false);
+		if (has_pubviaroot)
+			printTableAddCell(&cont, PQgetvalue(res, i, 8), false, false);
 
 		if (!puballtables)
 		{
-- 
2.43.0

