PS_addFooterToPublicationOrTableDesc.diff
application/octet-stream
Filename: PS_addFooterToPublicationOrTableDesc.diff
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/bin/psql/describe.c | 51 | 31 |
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 6b72745..482cca6 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1561,49 +1561,69 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
}
/*
- * If is_tbl_desc is true add footer to table description else add footer to
- * publication description.
+ * Add a footer to a publication description or a table description.
+ *
+ * 'is_pub_desc' - true for a pub desc; false for a table desc
+ * 'as_schema' - true if the pub_desc only shows schemas, otherwise false
*/
static bool
-addFooterToPublicationOrTableDesc(PQExpBuffer buf, const char *footermsg,
- bool as_schema, printTableContent *const cont,
- bool is_tbl_desc)
+addFooterToPublicationOrTableDesc(PQExpBuffer buf,
+ printTableContent *const cont,
+ const char *footermsg,
+ bool is_pub_desc, bool as_schema)
{
PGresult *res;
- int count = 0;
- int i = 0;
- int col = is_tbl_desc ? 0 : 1;
+ int count;
+ int col = is_pub_desc ? 1 : 0;
res = PSQLexec(buf->data);
if (!res)
return false;
- else
- count = PQntuples(res);
+ count = PQntuples(res);
if (count > 0)
printTableAddFooter(cont, footermsg);
- /*---------------------------------------------------
- * Publication/ table description columns:
- * [0]: schema name (nspname)
- * [col]: table name (relname) / publication name (pubname)
- * [col + 1]: row filter expression (prqual), may be NULL
- * [col + 2]: column list (comma-separated), may be NULL
- * [col + 3]: except flag ("t" if EXCEPT, else "f")
- *---------------------------------------------------
+ /*--------------------------------------------------------------
+ * Description columns:
+ *
+ * PUB TBL
+ * [0] - : schema name (nspname)
+ * [col] - : table name (relname)
+ * - [col] : publication name (pubname)
+ * [col+1] [col+1]: row filter expression (prqual), may be NULL
+ * [col+2] [col+1]: column list (comma-separated), may be NULL
+ * [col+3] [col+1]: except flag ("t" if EXCEPT, else "f")
+ *--------------------------------------------------------------
*/
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
- if (as_schema)
- printfPQExpBuffer(buf, " \"%s\"", PQgetvalue(res, i, 0));
- else
+ printfPQExpBuffer(buf, " "); /* indent */
+
+ /* Footers entries for a publication description or a table description */
+ if (is_pub_desc)
{
- if (is_tbl_desc)
- printfPQExpBuffer(buf, " \"%s\"", PQgetvalue(res, i, col));
+ if (as_schema)
+ {
+ /* Schemas of the publication... */
+ appendPQExpBuffer(buf, "\"%s\"", PQgetvalue(res, i, 0));
+ }
else
- printfPQExpBuffer(buf, " \"%s.%s\"", PQgetvalue(res, i, 0),
+ {
+ /* Tables of the publication... */
+ appendPQExpBuffer(buf, "\"%s.%s\"", PQgetvalue(res, i, 0),
PQgetvalue(res, i, col));
+ }
+ }
+ else
+ {
+ /* Publications of the table... */
+ appendPQExpBuffer(buf, "\"%s\"", PQgetvalue(res, i, col));
+ }
+ /* Common footer output for column list and/or row filter */
+ if (!as_schema)
+ {
if (!PQgetisnull(res, i, col + 2))
{
if (strcmp(PQgetvalue(res, i, col + 3), "t") == 0)
@@ -3192,7 +3212,7 @@ describeOneTableDetails(const char *schemaname,
oid, oid);
}
- if (!addFooterToPublicationOrTableDesc(&buf, _("Publications:"), false, &cont, true))
+ if (!addFooterToPublicationOrTableDesc(&buf, &cont, _("Publications:"), false, false))
goto error_return;
}
@@ -6755,7 +6775,7 @@ describePublications(const char *pattern)
" AND pr.prpubid = '%s'\n", pubid);
appendPQExpBuffer(&buf, "ORDER BY 1,2");
- if (!addFooterToPublicationOrTableDesc(&buf, _("Tables:"), false, &cont, false))
+ if (!addFooterToPublicationOrTableDesc(&buf, &cont, _("Tables:"), true, false))
goto error_return;
if (pset.sversion >= 150000)
@@ -6767,8 +6787,8 @@ describePublications(const char *pattern)
" JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
"WHERE pn.pnpubid = '%s'\n"
"ORDER BY 1", pubid);
- if (!addFooterToPublicationOrTableDesc(&buf, _("Tables from schemas:"),
- true, &cont, false))
+ if (!addFooterToPublicationOrTableDesc(&buf, &cont,
+ _("Tables from schemas:"), true, true))
goto error_return;
}
}
@@ -6784,8 +6804,8 @@ describePublications(const char *pattern)
"WHERE pr.prpubid = '%s'\n"
" AND pr.prexcept\n"
"ORDER BY 1", pubid);
- if (!addFooterToPublicationOrTableDesc(&buf, _("Except tables:"),
- true, &cont, false))
+ if (!addFooterToPublicationOrTableDesc(&buf, &cont,
+ _("Except tables:"), true, true))
goto error_return;
}
}