From 1fec4fd1bc2d891a6aa7f48d914a008d7bd87c70 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 29 Jul 2026 09:08:29 +1000 Subject: [PATCH v2] Fix escapes for psql describe schema patterns psql \dn was building the query with a raw '%s' substitution of the user-supplied pattern, so a pattern containing a single quote (\dn "it's a bug") broke out of the string literal and produced a syntax error on the server. Fixed by using a pattern escape function instead of raw-substitution. Author: Peter Smith Reviewed-by: Steven Niu Reviewed by: Jim Jones Discussion: https://www.postgresql.org/message-id/flat/SA5PPF230C70D4BFBD6006437E357AE7CF9A7CB2%40SA5PPF230C70D4B.namprd14.prod.outlook.com#c4b1b145852d2076db6590e0aae5c7da --- src/bin/psql/describe.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index ad9c8affb4f..635c77f993d 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -5327,10 +5327,14 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) "SELECT pubname \n" "FROM pg_catalog.pg_publication p\n" " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" - " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n" - "WHERE n.nspname = '%s'\n" - "ORDER BY 1", - pattern); + " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"); + + processSQLNamePattern(pset.db, &buf, pattern, false, false, + NULL, "n.nspname", NULL, + NULL, NULL, NULL); + + appendPQExpBufferStr(&buf, "ORDER BY 1;"); + result = PSQLexec(buf.data); if (!result) goto error_return; -- 2.47.3