From 19bd81061e98bc5b1e8102c367781705f649b8f3 Mon Sep 17 00:00:00 2001
From: David Rowley <dgrowley@gmail.com>
Date: Wed, 7 May 2025 22:31:44 +1200
Subject: [PATCH v1 3/3] Improve various new-to-v19 appendStringInfo calls

Similar to 928394b66 and 8461424fd, here we adjust a few new locations
which were not using the most suitable appendStringInfo* or
appendPQExpBuffer* function for the intended purpose.

Author: David Rowley <drowleyml@gmail.com>
---
 contrib/pg_plan_advice/pg_plan_advice.c    |   2 +-
 contrib/pg_plan_advice/pgpa_output.c       |   2 +-
 contrib/pg_plan_advice/pgpa_trove.c        |  14 +-
 src/backend/replication/logical/conflict.c |   2 +-
 src/backend/replication/logical/slotsync.c |   2 +-
 src/backend/utils/adt/ruleutils.c          |  37 +++--
 src/bin/pg_dump/pg_dump.c                  |   7 +-
 src/bin/pg_dump/pg_dumpall.c               |   4 +-
 src/bin/psql/describe.c                    | 164 ++++++++++-----------
 src/test/modules/test_escape/test_escape.c |   6 +-
 10 files changed, 119 insertions(+), 121 deletions(-)

diff --git a/contrib/pg_plan_advice/pg_plan_advice.c b/contrib/pg_plan_advice/pg_plan_advice.c
index 5629070faf4..299b0d02a86 100644
--- a/contrib/pg_plan_advice/pg_plan_advice.c
+++ b/contrib/pg_plan_advice/pg_plan_advice.c
@@ -330,7 +330,7 @@ pg_plan_advice_explain_feedback(ExplainState *es, List *feedback)
 
 		appendStringInfo(&buf, "%s /* ", item->defname);
 		pgpa_trove_append_flags(&buf, flags);
-		appendStringInfo(&buf, " */\n");
+		appendStringInfoString(&buf, " */\n");
 	}
 
 	pg_plan_advice_explain_text_multiline(es, "Supplied Plan Advice",
diff --git a/contrib/pg_plan_advice/pgpa_output.c b/contrib/pg_plan_advice/pgpa_output.c
index cd4411f350c..ed5a9340671 100644
--- a/contrib/pg_plan_advice/pgpa_output.c
+++ b/contrib/pg_plan_advice/pgpa_output.c
@@ -128,7 +128,7 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker,
 
 		if (buf->len > 0)
 			appendStringInfoChar(buf, '\n');
-		appendStringInfo(context.buf, "JOIN_ORDER(");
+		appendStringInfoString(context.buf, "JOIN_ORDER(");
 		pgpa_output_unrolled_join(&context, ujoin);
 		appendStringInfoChar(context.buf, ')');
 		pgpa_maybe_linebreak(context.buf, context.wrap_column);
diff --git a/contrib/pg_plan_advice/pgpa_trove.c b/contrib/pg_plan_advice/pgpa_trove.c
index 7ade0b5ca9c..486a42e8cc0 100644
--- a/contrib/pg_plan_advice/pgpa_trove.c
+++ b/contrib/pg_plan_advice/pgpa_trove.c
@@ -298,7 +298,7 @@ pgpa_cstring_trove_entry(pgpa_trove_entry *entry)
 	StringInfoData buf;
 
 	initStringInfo(&buf);
-	appendStringInfo(&buf, "%s", pgpa_cstring_advice_tag(entry->tag));
+	appendStringInfoString(&buf, pgpa_cstring_advice_tag(entry->tag));
 
 	/* JOIN_ORDER tags are transformed by pgpa_build_trove; undo that here */
 	if (entry->tag != PGPA_TAG_JOIN_ORDER)
@@ -346,18 +346,18 @@ pgpa_trove_append_flags(StringInfo buf, int flags)
 	if ((flags & PGPA_TE_MATCH_FULL) != 0)
 	{
 		Assert((flags & PGPA_TE_MATCH_PARTIAL) != 0);
-		appendStringInfo(buf, "matched");
+		appendStringInfoString(buf, "matched");
 	}
 	else if ((flags & PGPA_TE_MATCH_PARTIAL) != 0)
-		appendStringInfo(buf, "partially matched");
+		appendStringInfoString(buf, "partially matched");
 	else
-		appendStringInfo(buf, "not matched");
+		appendStringInfoString(buf, "not matched");
 	if ((flags & PGPA_TE_INAPPLICABLE) != 0)
-		appendStringInfo(buf, ", inapplicable");
+		appendStringInfoString(buf, ", inapplicable");
 	if ((flags & PGPA_TE_CONFLICTING) != 0)
-		appendStringInfo(buf, ", conflicting");
+		appendStringInfoString(buf, ", conflicting");
 	if ((flags & PGPA_TE_FAILED) != 0)
-		appendStringInfo(buf, ", failed");
+		appendStringInfoString(buf, ", failed");
 }
 
 /*
diff --git a/src/backend/replication/logical/conflict.c b/src/backend/replication/logical/conflict.c
index 6ff055c88aa..a9210415e43 100644
--- a/src/backend/replication/logical/conflict.c
+++ b/src/backend/replication/logical/conflict.c
@@ -363,7 +363,7 @@ errdetail_apply_conflict(EState *estate, ResultRelInfo *relinfo,
 									 localxmin, timestamptz_to_str(localts));
 			}
 			else
-				appendStringInfo(&err_detail, _("The row to be updated was deleted"));
+				appendStringInfoString(&err_detail, _("The row to be updated was deleted"));
 
 			break;
 
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index f90653e5232..2b1c5cf50d2 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -914,7 +914,7 @@ fetch_remote_slots(WalReceiverConn *wrconn, List *slot_names)
 			if (!first_slot)
 				appendStringInfoString(&query, ", ");
 
-			appendStringInfo(&query, "%s", quote_literal_cstr(slot_name));
+			appendStringInfoString(&query, quote_literal_cstr(slot_name));
 			first_slot = false;
 		}
 		appendStringInfoChar(&query, ')');
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 35083fcc733..090e8cc28c1 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -1691,7 +1691,7 @@ make_propgraphdef_elements(StringInfo buf, Oid pgrelid, char pgekind)
 			first = false;
 		}
 		else
-			appendStringInfo(buf, ",\n");
+			appendStringInfoString(buf, ",\n");
 
 		relname = get_rel_name(pgeform->pgerelid);
 		if (relname && strcmp(relname, NameStr(pgeform->pgealias)) == 0)
@@ -1707,7 +1707,7 @@ make_propgraphdef_elements(StringInfo buf, Oid pgrelid, char pgekind)
 		{
 			appendStringInfoString(buf, " KEY (");
 			decompile_column_index_array(datum, pgeform->pgerelid, false, buf);
-			appendStringInfoString(buf, ")");
+			appendStringInfoChar(buf, ')');
 		}
 		else
 			elog(ERROR, "null pgekey for element %u", pgeform->oid);
@@ -1741,7 +1741,7 @@ make_propgraphdef_elements(StringInfo buf, Oid pgrelid, char pgekind)
 				decompile_column_index_array(srckey, pgeform->pgerelid, false, buf);
 				appendStringInfo(buf, ") REFERENCES %s (", quote_identifier(NameStr(pgeform2->pgealias)));
 				decompile_column_index_array(srcref, pgeform2->pgerelid, false, buf);
-				appendStringInfoString(buf, ")");
+				appendStringInfoChar(buf, ')');
 			}
 			else
 				appendStringInfo(buf, " %s ", quote_identifier(NameStr(pgeform2->pgealias)));
@@ -1758,7 +1758,7 @@ make_propgraphdef_elements(StringInfo buf, Oid pgrelid, char pgekind)
 				decompile_column_index_array(destkey, pgeform->pgerelid, false, buf);
 				appendStringInfo(buf, ") REFERENCES %s (", quote_identifier(NameStr(pgeform2->pgealias)));
 				decompile_column_index_array(destref, pgeform2->pgerelid, false, buf);
-				appendStringInfoString(buf, ")");
+				appendStringInfoChar(buf, ')');
 			}
 			else
 				appendStringInfo(buf, " %s", quote_identifier(NameStr(pgeform2->pgealias)));
@@ -1768,7 +1768,7 @@ make_propgraphdef_elements(StringInfo buf, Oid pgrelid, char pgekind)
 		make_propgraphdef_labels(buf, pgeform->oid, NameStr(pgeform->pgealias), pgeform->pgerelid);
 	}
 	if (!first)
-		appendStringInfo(buf, "\n    )");
+		appendStringInfoString(buf, "\n    )");
 
 	systable_endscan(scan);
 	table_close(pgerel, AccessShareLock);
@@ -1848,7 +1848,7 @@ make_propgraphdef_labels(StringInfo buf, Oid elid, const char *elalias, Oid elre
 		{
 			/* If the default label is the only label, don't print anything. */
 			if (count != 1)
-				appendStringInfo(buf, " DEFAULT LABEL");
+				appendStringInfoString(buf, " DEFAULT LABEL");
 		}
 		else
 			appendStringInfo(buf, " LABEL %s", quote_identifier(osp->str));
@@ -1932,7 +1932,7 @@ make_propgraphdef_properties(StringInfo buf, Oid ellabelid, Oid elrelid)
 
 		context = deparse_context_for(get_relation_name(elrelid), elrelid);
 
-		appendStringInfo(buf, " PROPERTIES (");
+		appendStringInfoString(buf, " PROPERTIES (");
 
 		foreach(lc, outlist)
 		{
@@ -1943,20 +1943,20 @@ make_propgraphdef_properties(StringInfo buf, Oid ellabelid, Oid elrelid)
 			if (first)
 				first = false;
 			else
-				appendStringInfo(buf, ", ");
+				appendStringInfoString(buf, ", ");
 
 			if (IsA(expr, Var) && strcmp(propname, get_attname(elrelid, castNode(Var, expr)->varattno, false)) == 0)
-				appendStringInfo(buf, "%s", quote_identifier(propname));
+				appendStringInfoString(buf, quote_identifier(propname));
 			else
 				appendStringInfo(buf, "%s AS %s",
 								 deparse_expression_pretty(expr, context, false, false, 0, 0),
 								 quote_identifier(propname));
 		}
 
-		appendStringInfo(buf, ")");
+		appendStringInfoChar(buf, ')');
 	}
 	else
-		appendStringInfo(buf, " NO PROPERTIES");
+		appendStringInfoString(buf, " NO PROPERTIES");
 }
 
 /*
@@ -8008,7 +8008,7 @@ get_graph_label_expr(Node *label_expr, deparse_context *context)
 					if (!first)
 					{
 						if (be->boolop == OR_EXPR)
-							appendStringInfoString(buf, "|");
+							appendStringInfoChar(buf, '|');
 					}
 					else
 						first = false;
@@ -8041,7 +8041,7 @@ get_path_pattern_expr_def(List *path_pattern_expr, deparse_context *context)
 		switch (gep->kind)
 		{
 			case VERTEX_PATTERN:
-				appendStringInfoString(buf, "(");
+				appendStringInfoChar(buf, '(');
 				break;
 			case EDGE_PATTERN_LEFT:
 				appendStringInfoString(buf, "<-[");
@@ -8051,7 +8051,7 @@ get_path_pattern_expr_def(List *path_pattern_expr, deparse_context *context)
 				appendStringInfoString(buf, "-[");
 				break;
 			case PAREN_EXPR:
-				appendStringInfoString(buf, "(");
+				appendStringInfoChar(buf, '(');
 				break;
 		}
 
@@ -8086,7 +8086,7 @@ get_path_pattern_expr_def(List *path_pattern_expr, deparse_context *context)
 		switch (gep->kind)
 		{
 			case VERTEX_PATTERN:
-				appendStringInfoString(buf, ")");
+				appendStringInfoChar(buf, ')');
 				break;
 			case EDGE_PATTERN_LEFT:
 			case EDGE_PATTERN_ANY:
@@ -8096,7 +8096,7 @@ get_path_pattern_expr_def(List *path_pattern_expr, deparse_context *context)
 				appendStringInfoString(buf, "]->");
 				break;
 			case PAREN_EXPR:
-				appendStringInfoString(buf, ")");
+				appendStringInfoChar(buf, ')');
 				break;
 		}
 
@@ -13111,8 +13111,7 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
 						appendStringInfoString(buf, quote_identifier(te->resname));
 					}
 				}
-				appendStringInfoString(buf, ")");
-				appendStringInfoString(buf, ")");
+				appendStringInfoString(buf, "))");
 				break;
 			case RTE_VALUES:
 				/* Values list RTE */
@@ -13366,7 +13365,7 @@ get_for_portion_of(ForPortionOfExpr *forPortionOf, deparse_context *context)
 		{
 			appendStringInfoString(context->buf, " (");
 			get_rule_expr(forPortionOf->targetRange, context, false);
-			appendStringInfoString(context->buf, ")");
+			appendStringInfoChar(context->buf, ')');
 		}
 	}
 }
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index d34240073bb..1ca03d6b278 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4720,7 +4720,7 @@ dumpPublication(Archive *fout, const PublicationInfo *pubinfo)
 			appendPQExpBuffer(query, "TABLE ONLY %s", fmtQualifiedDumpable(tbinfo));
 		}
 		if (n_except > 0)
-			appendPQExpBufferStr(query, ")");
+			appendPQExpBufferChar(query, ')');
 
 		if (pubinfo->puballsequences)
 			appendPQExpBufferStr(query, ", ALL SEQUENCES");
@@ -5272,8 +5272,7 @@ getSubscriptions(Archive *fout)
 		appendPQExpBufferStr(query,
 							 " s.submaxretention,\n");
 	else
-		appendPQExpBuffer(query,
-						  " 0 AS submaxretention,\n");
+		appendPQExpBufferStr(query, " 0 AS submaxretention,\n");
 
 	if (fout->remoteVersion >= 190000)
 		appendPQExpBufferStr(query,
@@ -5592,7 +5591,7 @@ dumpSubscription(Archive *fout, const SubscriptionInfo *subinfo)
 	}
 	else
 	{
-		appendPQExpBuffer(query, "CONNECTION ");
+		appendPQExpBufferStr(query, "CONNECTION ");
 		appendStringLiteralAH(query, subinfo->subconninfo, fout);
 	}
 
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 20cdd2d92f0..9e904f76baa 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -728,7 +728,7 @@ main(int argc, char *argv[])
 		resetPQExpBuffer(qry);
 
 		/* Put the correct escape string behavior into the archive. */
-		appendPQExpBuffer(qry, "SET standard_conforming_strings = 'on';\n");
+		appendPQExpBufferStr(qry, "SET standard_conforming_strings = 'on';\n");
 		ArchiveEntry(fout,
 					 nilCatalogId,	/* catalog ID */
 					 createDumpId(),	/* dump ID */
@@ -1505,7 +1505,7 @@ dumpRoleMembership(PGconn *conn)
 					appendPQExpBuffer(querybuf, " WITH %s", optbuf->data);
 				if (dump_this_grantor)
 					appendPQExpBuffer(querybuf, " GRANTED BY %s", fmtId(grantor));
-				appendPQExpBuffer(querybuf, ";\n");
+				appendPQExpBufferStr(querybuf, ";\n");
 
 				if (archDumpFormat == archNull)
 					fprintf(OPF, "%s", querybuf->data);
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 4e8ff00394a..871bf70d1ff 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1510,12 +1510,12 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
 
 	printfPQExpBuffer(&buf, "/* %s */\n",
 					  _("Get matching relations to describe"));
-	appendPQExpBuffer(&buf,
-					  "SELECT c.oid,\n"
-					  "  n.nspname,\n"
-					  "  c.relname\n"
-					  "FROM pg_catalog.pg_class c\n"
-					  "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
+	appendPQExpBufferStr(&buf,
+						 "SELECT c.oid,\n"
+						 "  n.nspname,\n"
+						 "  c.relname\n"
+						 "FROM pg_catalog.pg_class c\n"
+						 "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
 
 	if (!showSystem && !pattern)
 		appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
@@ -2027,7 +2027,7 @@ describeOneTableDetails(const char *schemaname,
 	cols = 0;
 	printfPQExpBuffer(&buf, "/* %s */\n",
 					  _("Get per-column information for one relation"));
-	appendPQExpBuffer(&buf, "SELECT a.attname");
+	appendPQExpBufferStr(&buf, "SELECT a.attname");
 	attname_col = cols++;
 	appendPQExpBufferStr(&buf, ",\n  pg_catalog.format_type(a.atttypid, a.atttypmod)");
 	atttype_col = cols++;
@@ -2331,9 +2331,9 @@ describeOneTableDetails(const char *schemaname,
 
 		printfPQExpBuffer(&buf, "/* %s */\n",
 						  _("Get partitioning information for this partition"));
-		appendPQExpBuffer(&buf,
-						  "SELECT inhparent::pg_catalog.regclass,\n"
-						  "  pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n  ");
+		appendPQExpBufferStr(&buf,
+							 "SELECT inhparent::pg_catalog.regclass,\n"
+							 "  pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n  ");
 
 		appendPQExpBufferStr(&buf,
 							 pset.sversion >= 140000 ? "inhdetachpending" :
@@ -2441,25 +2441,25 @@ describeOneTableDetails(const char *schemaname,
 		PGresult   *result;
 
 		printfPQExpBuffer(&buf, "/* %s */\n", _("Get index details"));
-		appendPQExpBuffer(&buf,
-						  "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
-						  "i.indisvalid,\n"
-						  "  (NOT i.indimmediate) AND "
-						  "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
-						  "WHERE conrelid = i.indrelid AND "
-						  "conindid = i.indexrelid AND "
-						  "contype IN (" CppAsString2(CONSTRAINT_PRIMARY) ","
-						  CppAsString2(CONSTRAINT_UNIQUE) ","
-						  CppAsString2(CONSTRAINT_EXCLUSION) ") AND "
-						  "condeferrable) AS condeferrable,\n"
-						  "  (NOT i.indimmediate) AND "
-						  "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
-						  "WHERE conrelid = i.indrelid AND "
-						  "conindid = i.indexrelid AND "
-						  "contype IN (" CppAsString2(CONSTRAINT_PRIMARY) ","
-						  CppAsString2(CONSTRAINT_UNIQUE) ","
-						  CppAsString2(CONSTRAINT_EXCLUSION) ") AND "
-						  "condeferred) AS condeferred,\n");
+		appendPQExpBufferStr(&buf,
+							 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
+							 "i.indisvalid,\n"
+							 "  (NOT i.indimmediate) AND "
+							 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
+							 "WHERE conrelid = i.indrelid AND "
+							 "conindid = i.indexrelid AND "
+							 "contype IN (" CppAsString2(CONSTRAINT_PRIMARY) ","
+							 CppAsString2(CONSTRAINT_UNIQUE) ","
+							 CppAsString2(CONSTRAINT_EXCLUSION) ") AND "
+							 "condeferrable) AS condeferrable,\n"
+							 "  (NOT i.indimmediate) AND "
+							 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
+							 "WHERE conrelid = i.indrelid AND "
+							 "conindid = i.indexrelid AND "
+							 "contype IN (" CppAsString2(CONSTRAINT_PRIMARY) ","
+							 CppAsString2(CONSTRAINT_UNIQUE) ","
+							 CppAsString2(CONSTRAINT_EXCLUSION) ") AND "
+							 "condeferred) AS condeferred,\n");
 
 		if (pset.sversion >= 90400)
 			appendPQExpBufferStr(&buf, "i.indisreplident,\n");
@@ -2563,12 +2563,12 @@ describeOneTableDetails(const char *schemaname,
 		if (tableinfo.hasindex)
 		{
 			printfPQExpBuffer(&buf, "/* %s */\n", _("Get indexes for this table"));
-			appendPQExpBuffer(&buf,
-							  "SELECT c2.relname, i.indisprimary, i.indisunique, "
-							  "i.indisclustered, i.indisvalid, "
-							  "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n  "
-							  "pg_catalog.pg_get_constraintdef(con.oid, true), "
-							  "contype, condeferrable, condeferred");
+			appendPQExpBufferStr(&buf,
+								 "SELECT c2.relname, i.indisprimary, i.indisunique, "
+								 "i.indisclustered, i.indisvalid, "
+								 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n  "
+								 "pg_catalog.pg_get_constraintdef(con.oid, true), "
+								 "contype, condeferrable, condeferred");
 			if (pset.sversion >= 90400)
 				appendPQExpBufferStr(&buf, ", i.indisreplident");
 			else
@@ -2827,7 +2827,7 @@ describeOneTableDetails(const char *schemaname,
 		{
 			printfPQExpBuffer(&buf, "/* %s */\n",
 							  _("Get row-level policies for this table"));
-			appendPQExpBuffer(&buf, "SELECT pol.polname,");
+			appendPQExpBufferStr(&buf, "SELECT pol.polname,");
 			if (pset.sversion >= 100000)
 				appendPQExpBufferStr(&buf,
 									 " pol.polpermissive,\n");
@@ -3011,18 +3011,18 @@ describeOneTableDetails(const char *schemaname,
 		{
 			printfPQExpBuffer(&buf, "/* %s */\n",
 							  _("Get extended statistics for this table"));
-			appendPQExpBuffer(&buf,
-							  "SELECT oid, "
-							  "stxrelid::pg_catalog.regclass, "
-							  "stxnamespace::pg_catalog.regnamespace AS nsp, "
-							  "stxname,\n"
-							  "  (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
-							  "   FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
-							  "   JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
-							  "        a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
-							  "  " CppAsString2(STATS_EXT_NDISTINCT) " = any(stxkind) AS ndist_enabled,\n"
-							  "  " CppAsString2(STATS_EXT_DEPENDENCIES) " = any(stxkind) AS deps_enabled,\n"
-							  "  " CppAsString2(STATS_EXT_MCV) " = any(stxkind) AS mcv_enabled,\n");
+			appendPQExpBufferStr(&buf,
+								 "SELECT oid, "
+								 "stxrelid::pg_catalog.regclass, "
+								 "stxnamespace::pg_catalog.regnamespace AS nsp, "
+								 "stxname,\n"
+								 "  (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
+								 "   FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
+								 "   JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
+								 "        a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
+								 "  " CppAsString2(STATS_EXT_NDISTINCT) " = any(stxkind) AS ndist_enabled,\n"
+								 "  " CppAsString2(STATS_EXT_DEPENDENCIES) " = any(stxkind) AS deps_enabled,\n"
+								 "  " CppAsString2(STATS_EXT_MCV) " = any(stxkind) AS mcv_enabled,\n");
 
 			if (pset.sversion >= 130000)
 				appendPQExpBufferStr(&buf, "  stxstattarget\n");
@@ -3439,10 +3439,10 @@ describeOneTableDetails(const char *schemaname,
 
 		printfPQExpBuffer(&buf, "/* %s */\n",
 						  _("Get triggers for this relation"));
-		appendPQExpBuffer(&buf,
-						  "SELECT t.tgname, "
-						  "pg_catalog.pg_get_triggerdef(t.oid, true), "
-						  "t.tgenabled, t.tgisinternal,\n");
+		appendPQExpBufferStr(&buf,
+							 "SELECT t.tgname, "
+							 "pg_catalog.pg_get_triggerdef(t.oid, true), "
+							 "t.tgenabled, t.tgisinternal,\n");
 
 		/*
 		 * Detect whether each trigger is inherited, and if so, get the name
@@ -3953,10 +3953,10 @@ describeRoles(const char *pattern, bool verbose, bool showSystem)
 	initPQExpBuffer(&buf);
 
 	printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching roles"));
-	appendPQExpBuffer(&buf,
-					  "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
-					  "  r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
-					  "  r.rolconnlimit, r.rolvaliduntil");
+	appendPQExpBufferStr(&buf,
+						 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
+						 "  r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
+						 "  r.rolconnlimit, r.rolvaliduntil");
 
 	if (verbose)
 	{
@@ -5646,12 +5646,12 @@ listTSParsersVerbose(const char *pattern)
 	initPQExpBuffer(&buf);
 
 	printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search parsers"));
-	appendPQExpBuffer(&buf,
-					  "SELECT p.oid,\n"
-					  "  n.nspname,\n"
-					  "  p.prsname\n"
-					  "FROM pg_catalog.pg_ts_parser p\n"
-					  "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
+	appendPQExpBufferStr(&buf,
+						 "SELECT p.oid,\n"
+						 "  n.nspname,\n"
+						 "  p.prsname\n"
+						 "FROM pg_catalog.pg_ts_parser p\n"
+						 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
 		);
 
 	if (!validateSQLNamePattern(&buf, pattern, false, false,
@@ -6027,16 +6027,16 @@ listTSConfigsVerbose(const char *pattern)
 	initPQExpBuffer(&buf);
 
 	printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search configurations"));
-	appendPQExpBuffer(&buf,
-					  "SELECT c.oid, c.cfgname,\n"
-					  "   n.nspname,\n"
-					  "   p.prsname,\n"
-					  "   np.nspname as pnspname\n"
-					  "FROM pg_catalog.pg_ts_config c\n"
-					  "   LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
-					  " pg_catalog.pg_ts_parser p\n"
-					  "   LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
-					  "WHERE  p.oid = c.cfgparser\n"
+	appendPQExpBufferStr(&buf,
+						 "SELECT c.oid, c.cfgname,\n"
+						 "   n.nspname,\n"
+						 "   p.prsname,\n"
+						 "   np.nspname as pnspname\n"
+						 "FROM pg_catalog.pg_ts_config c\n"
+						 "   LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
+						 " pg_catalog.pg_ts_parser p\n"
+						 "   LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
+						 "WHERE  p.oid = c.cfgparser\n"
 		);
 
 	if (!validateSQLNamePattern(&buf, pattern, true, false,
@@ -6522,9 +6522,9 @@ listExtensionContents(const char *pattern)
 	initPQExpBuffer(&buf);
 
 	printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed extensions"));
-	appendPQExpBuffer(&buf,
-					  "SELECT e.extname, e.oid\n"
-					  "FROM pg_catalog.pg_extension e\n");
+	appendPQExpBufferStr(&buf,
+						 "SELECT e.extname, e.oid\n"
+						 "FROM pg_catalog.pg_extension e\n");
 
 	if (!validateSQLNamePattern(&buf, pattern,
 								false, false,
@@ -6853,10 +6853,10 @@ describePublications(const char *pattern)
 	initPQExpBuffer(&buf);
 
 	printfPQExpBuffer(&buf, "/* %s */\n", _("Get details about matching publications"));
-	appendPQExpBuffer(&buf,
-					  "SELECT oid, pubname,\n"
-					  "  pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
-					  "  puballtables");
+	appendPQExpBufferStr(&buf,
+						 "SELECT oid, pubname,\n"
+						 "  pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
+						 "  puballtables");
 
 	if (has_pubsequence)
 		appendPQExpBufferStr(&buf,
@@ -6991,7 +6991,7 @@ describePublications(const char *pattern)
 			/* Get the tables for the specified publication */
 			printfPQExpBuffer(&buf, "/* %s */\n",
 							  _("Get tables published by this publication"));
-			appendPQExpBuffer(&buf, "SELECT n.nspname, c.relname");
+			appendPQExpBufferStr(&buf, "SELECT n.nspname, c.relname");
 			if (pset.sversion >= 150000)
 			{
 				appendPQExpBufferStr(&buf,
@@ -7018,9 +7018,9 @@ describePublications(const char *pattern)
 							  "  AND pr.prpubid = '%s'\n", pubid);
 
 			if (pset.sversion >= 190000)
-				appendPQExpBuffer(&buf, "  AND NOT pr.prexcept\n");
+				appendPQExpBufferStr(&buf, "  AND NOT pr.prexcept\n");
 
-			appendPQExpBuffer(&buf, "ORDER BY 1,2");
+			appendPQExpBufferStr(&buf, "ORDER BY 1,2");
 			if (!addFooterToPublicationDesc(&buf, _("Tables:"), false, &cont))
 				goto error_return;
 
diff --git a/src/test/modules/test_escape/test_escape.c b/src/test/modules/test_escape/test_escape.c
index 6dab4f2cf5b..6234a9bd129 100644
--- a/src/test/modules/test_escape/test_escape.c
+++ b/src/test/modules/test_escape/test_escape.c
@@ -192,7 +192,7 @@ test_gb18030_page_multiple(pe_test_config *tc)
 	testname = createPQExpBuffer();
 	appendPQExpBuffer(testname, ">repeat(%c, %zu)", input[0], input_len - 1);
 	escapify(testname, input + input_len - 1, 1);
-	appendPQExpBuffer(testname, "< - GB18030 - PQescapeLiteral");
+	appendPQExpBufferStr(testname, "< - GB18030 - PQescapeLiteral");
 
 	/* test itself */
 	PQsetClientEncoding(tc->conn, "GB18030");
@@ -229,9 +229,9 @@ test_gb18030_json(pe_test_config *tc)
 
 	/* name to describe the test */
 	testname = createPQExpBuffer();
-	appendPQExpBuffer(testname, ">");
+	appendPQExpBufferChar(testname, '>');
 	escapify(testname, input, input_len);
-	appendPQExpBuffer(testname, "< - GB18030 - pg_parse_json");
+	appendPQExpBufferStr(testname, "< - GB18030 - pg_parse_json");
 
 	/* test itself */
 	lex = makeJsonLexContextCstringLen(NULL, raw_buf->data, input_len,
-- 
2.51.0

