From 326c489012f020f8ef38e1187aea72b332d1b9a4 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 25 Mar 2021 12:08:51 +0100 Subject: [PATCH 6/6] fixup! Print publication WHERE condition in psql Make psql backward compatible. Also add necessary parentheses. --- src/bin/psql/describe.c | 11 +++++++---- src/test/regress/expected/publication.out | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 983ba512f7..6dce968414 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -6038,9 +6038,12 @@ describePublications(const char *pattern) if (!puballtables) { printfPQExpBuffer(&buf, - "SELECT n.nspname, c.relname,\n" - " pg_get_expr(pr.prqual, c.oid)\n" - "FROM pg_catalog.pg_class c,\n" + "SELECT n.nspname, c.relname"); + if (pset.sversion >= 140000) + appendPQExpBuffer(&buf, + ", pg_get_expr(pr.prqual, c.oid)"); + appendPQExpBuffer(&buf, + "\nFROM pg_catalog.pg_class c,\n" " pg_catalog.pg_namespace n,\n" " pg_catalog.pg_publication_rel pr\n" "WHERE c.relnamespace = n.oid\n" @@ -6070,7 +6073,7 @@ describePublications(const char *pattern) PQgetvalue(tabres, j, 1)); if (!PQgetisnull(tabres, j, 2)) - appendPQExpBuffer(&buf, " WHERE %s", + appendPQExpBuffer(&buf, " WHERE (%s)", PQgetvalue(tabres, j, 2)); printTableAddFooter(&cont, buf.data); diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index c8cf1b685e..da49a2e215 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -181,7 +181,7 @@ ERROR: cannot use a WHERE clause when removing table from publication "testpub5 --------------------------+------------+---------+---------+---------+-----------+---------- regress_publication_user | f | t | t | t | t | f Tables: - "public.testpub_rf_tbl3" WHERE ((e > 300) AND (e < 500)) + "public.testpub_rf_tbl3" WHERE (((e > 300) AND (e < 500))) DROP TABLE testpub_rf_tbl1; DROP TABLE testpub_rf_tbl2; -- 2.30.2