From 4d0556ae5395f3e28fe9616c51ea971f63d6a927 Mon Sep 17 00:00:00 2001 From: Amul Sul Date: Thu, 29 Apr 2021 02:15:37 -0400 Subject: [PATCH 2/2] WIP-POC-PSQL-change temp table description --- src/bin/psql/describe.c | 13 +++++++++++++ src/fe_utils/string_utils.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 3e39fdb5452..ea27f09b8a9 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1584,6 +1584,15 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem) nspname = PQgetvalue(res, i, 1); relname = PQgetvalue(res, i, 2); + /* Replace internal temp schema name */ + if (pset.sversion >= 140000) + { + if (strncmp(nspname, "pg_temp_", 8) == 0) + nspname = "pg_temp"; + else if (strncmp(nspname, "pg_toast_temp_", 14) == 0) + nspname = "pg_toast_temp"; + } + if (!describeOneTableDetails(nspname, relname, oid, verbose)) { PQclear(res); @@ -2396,6 +2405,10 @@ describeOneTableDetails(const char *schemaname, char *schemaname = PQgetvalue(result, 0, 0); char *relname = PQgetvalue(result, 0, 1); + /* Replace internal temporary schema name */ + if (strncmp(schemaname, "pg_temp_", 8) == 0) + schemaname = "pg_temp"; + printfPQExpBuffer(&tmpbuf, _("Owning table: \"%s.%s\""), schemaname, relname); printTableAddFooter(&cont, tmpbuf.data); diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c index 5b206c7481d..67c7a883b33 100644 --- a/src/fe_utils/string_utils.c +++ b/src/fe_utils/string_utils.c @@ -913,6 +913,14 @@ processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, { WHEREAND(); appendPQExpBuffer(buf, "%s OPERATOR(pg_catalog.~) ", schemavar); + + /* + * Internal temporary schema name could be different, strip out "$" + * from pattern to relax the match. + */ + if (strcmp(schemabuf.data, "^(pg_temp)$") == 0 || + strcmp(schemabuf.data, "^(pg_toast_temp)$") == 0) + schemabuf.data[schemabuf.len-1] = '\0'; appendStringLiteralConn(buf, schemabuf.data, conn); if (PQserverVersion(conn) >= 120000) appendPQExpBufferStr(buf, " COLLATE pg_catalog.default"); -- 2.18.0