Commit 915379c3 authored by Peter Eisentraut's avatar Peter Eisentraut

psql: Improve display of "for all tables" publications

Show "All tables" property in \dRp and \dRp+.  Don't list tables for
such publications in \dRp+, since it's redundant and the list could be
very long.

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Author: Jeff Janes <jeff.janes@gmail.com>
parent 6c6a1149
...@@ -5047,7 +5047,7 @@ listPublications(const char *pattern) ...@@ -5047,7 +5047,7 @@ listPublications(const char *pattern)
PQExpBufferData buf; PQExpBufferData buf;
PGresult *res; PGresult *res;
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
static const bool translate_columns[] = {false, false, false, false, false}; static const bool translate_columns[] = {false, false, false, false, false, false};
if (pset.sversion < 100000) if (pset.sversion < 100000)
{ {
...@@ -5064,11 +5064,13 @@ listPublications(const char *pattern) ...@@ -5064,11 +5064,13 @@ listPublications(const char *pattern)
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT pubname AS \"%s\",\n" "SELECT pubname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n" " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
" puballtables AS \"%s\",\n"
" pubinsert AS \"%s\",\n" " pubinsert AS \"%s\",\n"
" pubupdate AS \"%s\",\n" " pubupdate AS \"%s\",\n"
" pubdelete AS \"%s\"\n", " pubdelete AS \"%s\"\n",
gettext_noop("Name"), gettext_noop("Name"),
gettext_noop("Owner"), gettext_noop("Owner"),
gettext_noop("All tables"),
gettext_noop("Inserts"), gettext_noop("Inserts"),
gettext_noop("Updates"), gettext_noop("Updates"),
gettext_noop("Deletes")); gettext_noop("Deletes"));
...@@ -5145,7 +5147,7 @@ describePublications(const char *pattern) ...@@ -5145,7 +5147,7 @@ describePublications(const char *pattern)
for (i = 0; i < PQntuples(res); i++) for (i = 0; i < PQntuples(res); i++)
{ {
const char align = 'l'; const char align = 'l';
int ncols = 3; int ncols = 4;
int nrows = 1; int nrows = 1;
int tables = 0; int tables = 0;
PGresult *tabres; PGresult *tabres;
...@@ -5161,25 +5163,18 @@ describePublications(const char *pattern) ...@@ -5161,25 +5163,18 @@ describePublications(const char *pattern)
printfPQExpBuffer(&title, _("Publication %s"), pubname); printfPQExpBuffer(&title, _("Publication %s"), pubname);
printTableInit(&cont, &myopt, title.data, ncols, nrows); printTableInit(&cont, &myopt, title.data, ncols, nrows);
printTableAddHeader(&cont, gettext_noop("All tables"), true, align);
printTableAddHeader(&cont, gettext_noop("Inserts"), true, align); printTableAddHeader(&cont, gettext_noop("Inserts"), true, align);
printTableAddHeader(&cont, gettext_noop("Updates"), true, align); printTableAddHeader(&cont, gettext_noop("Updates"), true, align);
printTableAddHeader(&cont, gettext_noop("Deletes"), true, align); printTableAddHeader(&cont, gettext_noop("Deletes"), true, align);
printTableAddCell(&cont, PQgetvalue(res, i, 2), false, false);
printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false); printTableAddCell(&cont, PQgetvalue(res, i, 3), false, false);
printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false); printTableAddCell(&cont, PQgetvalue(res, i, 4), false, false);
printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false); printTableAddCell(&cont, PQgetvalue(res, i, 5), false, false);
if (puballtables) if (!puballtables)
printfPQExpBuffer(&buf, {
"SELECT n.nspname, c.relname\n"
"FROM pg_catalog.pg_class c,\n"
" pg_catalog.pg_namespace n\n"
"WHERE c.relnamespace = n.oid\n"
" AND c.relkind = " CppAsString2(RELKIND_RELATION) "\n"
" AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"
"ORDER BY 1,2");
else
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT n.nspname, c.relname\n" "SELECT n.nspname, c.relname\n"
"FROM pg_catalog.pg_class c,\n" "FROM pg_catalog.pg_class c,\n"
...@@ -5190,30 +5185,31 @@ describePublications(const char *pattern) ...@@ -5190,30 +5185,31 @@ describePublications(const char *pattern)
" AND pr.prpubid = '%s'\n" " AND pr.prpubid = '%s'\n"
"ORDER BY 1,2", pubid); "ORDER BY 1,2", pubid);
tabres = PSQLexec(buf.data); tabres = PSQLexec(buf.data);
if (!tabres) if (!tabres)
{ {
printTableCleanup(&cont); printTableCleanup(&cont);
PQclear(res); PQclear(res);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
termPQExpBuffer(&title); termPQExpBuffer(&title);
return false; return false;
} }
else else
tables = PQntuples(tabres); tables = PQntuples(tabres);
if (tables > 0) if (tables > 0)
printTableAddFooter(&cont, _("Tables:")); printTableAddFooter(&cont, _("Tables:"));
for (j = 0; j < tables; j++) for (j = 0; j < tables; j++)
{ {
printfPQExpBuffer(&buf, " \"%s.%s\"", printfPQExpBuffer(&buf, " \"%s.%s\"",
PQgetvalue(tabres, j, 0), PQgetvalue(tabres, j, 0),
PQgetvalue(tabres, j, 1)); PQgetvalue(tabres, j, 1));
printTableAddFooter(&cont, buf.data); printTableAddFooter(&cont, buf.data);
}
PQclear(tabres);
} }
PQclear(tabres);
printTable(&cont, pset.queryFout, false, pset.logfile); printTable(&cont, pset.queryFout, false, pset.logfile);
printTableCleanup(&cont); printTableCleanup(&cont);
......
...@@ -21,20 +21,20 @@ ERROR: unrecognized publication parameter: foo ...@@ -21,20 +21,20 @@ ERROR: unrecognized publication parameter: foo
CREATE PUBLICATION testpub_xxx WITH (publish = 'cluster, vacuum'); CREATE PUBLICATION testpub_xxx WITH (publish = 'cluster, vacuum');
ERROR: unrecognized "publish" value: "cluster" ERROR: unrecognized "publish" value: "cluster"
\dRp \dRp
List of publications List of publications
Name | Owner | Inserts | Updates | Deletes Name | Owner | All tables | Inserts | Updates | Deletes
--------------------+--------------------------+---------+---------+--------- --------------------+--------------------------+------------+---------+---------+---------
testpib_ins_trunct | regress_publication_user | t | f | f testpib_ins_trunct | regress_publication_user | f | t | f | f
testpub_default | regress_publication_user | f | t | f testpub_default | regress_publication_user | f | f | t | f
(2 rows) (2 rows)
ALTER PUBLICATION testpub_default SET (publish = 'insert, update, delete'); ALTER PUBLICATION testpub_default SET (publish = 'insert, update, delete');
\dRp \dRp
List of publications List of publications
Name | Owner | Inserts | Updates | Deletes Name | Owner | All tables | Inserts | Updates | Deletes
--------------------+--------------------------+---------+---------+--------- --------------------+--------------------------+------------+---------+---------+---------
testpib_ins_trunct | regress_publication_user | t | f | f testpib_ins_trunct | regress_publication_user | f | t | f | f
testpub_default | regress_publication_user | t | t | t testpub_default | regress_publication_user | f | t | t | t
(2 rows) (2 rows)
--- adding tables --- adding tables
...@@ -75,6 +75,13 @@ Indexes: ...@@ -75,6 +75,13 @@ Indexes:
Publications: Publications:
"testpub_foralltables" "testpub_foralltables"
\dRp+ testpub_foralltables
Publication testpub_foralltables
All tables | Inserts | Updates | Deletes
------------+---------+---------+---------
t | t | t | f
(1 row)
DROP TABLE testpub_tbl2; DROP TABLE testpub_tbl2;
DROP PUBLICATION testpub_foralltables; DROP PUBLICATION testpub_foralltables;
CREATE TABLE testpub_tbl3 (a int); CREATE TABLE testpub_tbl3 (a int);
...@@ -82,19 +89,19 @@ CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3); ...@@ -82,19 +89,19 @@ CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3; CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3; CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
\dRp+ testpub3 \dRp+ testpub3
Publication testpub3 Publication testpub3
Inserts | Updates | Deletes All tables | Inserts | Updates | Deletes
---------+---------+--------- ------------+---------+---------+---------
t | t | t f | t | t | t
Tables: Tables:
"public.testpub_tbl3" "public.testpub_tbl3"
"public.testpub_tbl3a" "public.testpub_tbl3a"
\dRp+ testpub4 \dRp+ testpub4
Publication testpub4 Publication testpub4
Inserts | Updates | Deletes All tables | Inserts | Updates | Deletes
---------+---------+--------- ------------+---------+---------+---------
t | t | t f | t | t | t
Tables: Tables:
"public.testpub_tbl3" "public.testpub_tbl3"
...@@ -112,10 +119,10 @@ ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl ...@@ -112,10 +119,10 @@ ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1; CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1;
ERROR: publication "testpub_fortbl" already exists ERROR: publication "testpub_fortbl" already exists
\dRp+ testpub_fortbl \dRp+ testpub_fortbl
Publication testpub_fortbl Publication testpub_fortbl
Inserts | Updates | Deletes All tables | Inserts | Updates | Deletes
---------+---------+--------- ------------+---------+---------+---------
t | t | t f | t | t | t
Tables: Tables:
"pub_test.testpub_nopk" "pub_test.testpub_nopk"
"public.testpub_tbl1" "public.testpub_tbl1"
...@@ -158,10 +165,10 @@ Publications: ...@@ -158,10 +165,10 @@ Publications:
"testpub_fortbl" "testpub_fortbl"
\dRp+ testpub_default \dRp+ testpub_default
Publication testpub_default Publication testpub_default
Inserts | Updates | Deletes All tables | Inserts | Updates | Deletes
---------+---------+--------- ------------+---------+---------+---------
t | t | t f | t | t | t
Tables: Tables:
"pub_test.testpub_nopk" "pub_test.testpub_nopk"
"public.testpub_tbl1" "public.testpub_tbl1"
...@@ -203,10 +210,10 @@ DROP TABLE testpub_parted; ...@@ -203,10 +210,10 @@ DROP TABLE testpub_parted;
DROP VIEW testpub_view; DROP VIEW testpub_view;
DROP TABLE testpub_tbl1; DROP TABLE testpub_tbl1;
\dRp+ testpub_default \dRp+ testpub_default
Publication testpub_default Publication testpub_default
Inserts | Updates | Deletes All tables | Inserts | Updates | Deletes
---------+---------+--------- ------------+---------+---------+---------
t | t | t f | t | t | t
(1 row) (1 row)
-- fail - must be owner of publication -- fail - must be owner of publication
...@@ -216,20 +223,20 @@ ERROR: must be owner of publication testpub_default ...@@ -216,20 +223,20 @@ ERROR: must be owner of publication testpub_default
RESET ROLE; RESET ROLE;
ALTER PUBLICATION testpub_default RENAME TO testpub_foo; ALTER PUBLICATION testpub_default RENAME TO testpub_foo;
\dRp testpub_foo \dRp testpub_foo
List of publications List of publications
Name | Owner | Inserts | Updates | Deletes Name | Owner | All tables | Inserts | Updates | Deletes
-------------+--------------------------+---------+---------+--------- -------------+--------------------------+------------+---------+---------+---------
testpub_foo | regress_publication_user | t | t | t testpub_foo | regress_publication_user | f | t | t | t
(1 row) (1 row)
-- rename back to keep the rest simple -- rename back to keep the rest simple
ALTER PUBLICATION testpub_foo RENAME TO testpub_default; ALTER PUBLICATION testpub_foo RENAME TO testpub_default;
ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2; ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2;
\dRp testpub_default \dRp testpub_default
List of publications List of publications
Name | Owner | Inserts | Updates | Deletes Name | Owner | All tables | Inserts | Updates | Deletes
-----------------+---------------------------+---------+---------+--------- -----------------+---------------------------+------------+---------+---------+---------
testpub_default | regress_publication_user2 | t | t | t testpub_default | regress_publication_user2 | f | t | t | t
(1 row) (1 row)
DROP PUBLICATION testpub_default; DROP PUBLICATION testpub_default;
......
...@@ -45,6 +45,7 @@ ALTER PUBLICATION testpub_foralltables SET TABLE pub_test.testpub_nopk; ...@@ -45,6 +45,7 @@ ALTER PUBLICATION testpub_foralltables SET TABLE pub_test.testpub_nopk;
SELECT pubname, puballtables FROM pg_publication WHERE pubname = 'testpub_foralltables'; SELECT pubname, puballtables FROM pg_publication WHERE pubname = 'testpub_foralltables';
\d+ testpub_tbl2 \d+ testpub_tbl2
\dRp+ testpub_foralltables
DROP TABLE testpub_tbl2; DROP TABLE testpub_tbl2;
DROP PUBLICATION testpub_foralltables; DROP PUBLICATION testpub_foralltables;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment