From d7acf6cc4a1ae53fcd5b4a8a702c43a267f33ba3 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Sat, 1 Jan 2011 17:43:37 -0500
Subject: [PATCH] Fix pg_dump support for security labels on columns.

Along the way, correct an erroneous comment.
---
 src/bin/pg_dump/pg_dump.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index b35a5457f94..08288e871a9 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -10730,7 +10730,7 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
 							tbinfo->dobj.catId.oid,
 							&labels);
 
-	/* If comments exist, build SECURITY LABEL statements */
+	/* If security labels exist, build SECURITY LABEL statements */
 	if (nlabels <= 0)
 		return;
 
@@ -10753,9 +10753,9 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
 		else
 		{
 			colname = getAttrName(objsubid, tbinfo);
-			appendPQExpBuffer(target, "COLUMN %s.%s",
-							  fmtId(tbinfo->dobj.name),
-							  fmtId(colname));
+			/* first fmtId result must be consumed before calling it again */
+			appendPQExpBuffer(target, "COLUMN %s", fmtId(tbinfo->dobj.name));
+			appendPQExpBuffer(target, ".%s", fmtId(colname));
 		}
 		appendPQExpBuffer(query, "SECURITY LABEL FOR %s ON %s IS ",
 						  fmtId(provider), target->data);
-- 
GitLab