Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit915379c

Browse files
committed
psql: Improve display of "for all tables" publications
Show "All tables" property in \dRp and \dRp+. Don't list tables forsuch publications in \dRp+, since it's redundant and the list could bevery long.Author: Masahiko Sawada <sawada.mshk@gmail.com>Author: Jeff Janes <jeff.janes@gmail.com>
1 parent6c6a114 commit915379c

File tree

3 files changed

+75
-71
lines changed

3 files changed

+75
-71
lines changed

‎src/bin/psql/describe.c

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,7 +5047,7 @@ listPublications(const char *pattern)
50475047
PQExpBufferDatabuf;
50485048
PGresult*res;
50495049
printQueryOptmyopt=pset.popt;
5050-
staticconstbooltranslate_columns[]= {false, false, false, false, false};
5050+
staticconstbooltranslate_columns[]= {false, false, false, false, false, false};
50515051

50525052
if (pset.sversion<100000)
50535053
{
@@ -5064,11 +5064,13 @@ listPublications(const char *pattern)
50645064
printfPQExpBuffer(&buf,
50655065
"SELECT pubname AS \"%s\",\n"
50665066
" pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
5067+
" puballtables AS \"%s\",\n"
50675068
" pubinsert AS \"%s\",\n"
50685069
" pubupdate AS \"%s\",\n"
50695070
" pubdelete AS \"%s\"\n",
50705071
gettext_noop("Name"),
50715072
gettext_noop("Owner"),
5073+
gettext_noop("All tables"),
50725074
gettext_noop("Inserts"),
50735075
gettext_noop("Updates"),
50745076
gettext_noop("Deletes"));
@@ -5145,7 +5147,7 @@ describePublications(const char *pattern)
51455147
for (i=0;i<PQntuples(res);i++)
51465148
{
51475149
constcharalign='l';
5148-
intncols=3;
5150+
intncols=4;
51495151
intnrows=1;
51505152
inttables=0;
51515153
PGresult*tabres;
@@ -5161,25 +5163,18 @@ describePublications(const char *pattern)
51615163
printfPQExpBuffer(&title,_("Publication %s"),pubname);
51625164
printTableInit(&cont,&myopt,title.data,ncols,nrows);
51635165

5166+
printTableAddHeader(&cont,gettext_noop("All tables"), true,align);
51645167
printTableAddHeader(&cont,gettext_noop("Inserts"), true,align);
51655168
printTableAddHeader(&cont,gettext_noop("Updates"), true,align);
51665169
printTableAddHeader(&cont,gettext_noop("Deletes"), true,align);
51675170

5171+
printTableAddCell(&cont,PQgetvalue(res,i,2), false, false);
51685172
printTableAddCell(&cont,PQgetvalue(res,i,3), false, false);
51695173
printTableAddCell(&cont,PQgetvalue(res,i,4), false, false);
51705174
printTableAddCell(&cont,PQgetvalue(res,i,5), false, false);
51715175

5172-
if (puballtables)
5173-
printfPQExpBuffer(&buf,
5174-
"SELECT n.nspname, c.relname\n"
5175-
"FROM pg_catalog.pg_class c,\n"
5176-
" pg_catalog.pg_namespace n\n"
5177-
"WHERE c.relnamespace = n.oid\n"
5178-
" AND c.relkind = "CppAsString2(RELKIND_RELATION)"\n"
5179-
" AND n.nspname <> 'pg_catalog'\n"
5180-
" AND n.nspname <> 'information_schema'\n"
5181-
"ORDER BY 1,2");
5182-
else
5176+
if (!puballtables)
5177+
{
51835178
printfPQExpBuffer(&buf,
51845179
"SELECT n.nspname, c.relname\n"
51855180
"FROM pg_catalog.pg_class c,\n"
@@ -5190,30 +5185,31 @@ describePublications(const char *pattern)
51905185
" AND pr.prpubid = '%s'\n"
51915186
"ORDER BY 1,2",pubid);
51925187

5193-
tabres=PSQLexec(buf.data);
5194-
if (!tabres)
5195-
{
5196-
printTableCleanup(&cont);
5197-
PQclear(res);
5198-
termPQExpBuffer(&buf);
5199-
termPQExpBuffer(&title);
5200-
return false;
5201-
}
5202-
else
5203-
tables=PQntuples(tabres);
5188+
tabres=PSQLexec(buf.data);
5189+
if (!tabres)
5190+
{
5191+
printTableCleanup(&cont);
5192+
PQclear(res);
5193+
termPQExpBuffer(&buf);
5194+
termPQExpBuffer(&title);
5195+
return false;
5196+
}
5197+
else
5198+
tables=PQntuples(tabres);
52045199

5205-
if (tables>0)
5206-
printTableAddFooter(&cont,_("Tables:"));
5200+
if (tables>0)
5201+
printTableAddFooter(&cont,_("Tables:"));
52075202

5208-
for (j=0;j<tables;j++)
5209-
{
5210-
printfPQExpBuffer(&buf," \"%s.%s\"",
5211-
PQgetvalue(tabres,j,0),
5212-
PQgetvalue(tabres,j,1));
5203+
for (j=0;j<tables;j++)
5204+
{
5205+
printfPQExpBuffer(&buf," \"%s.%s\"",
5206+
PQgetvalue(tabres,j,0),
5207+
PQgetvalue(tabres,j,1));
52135208

5214-
printTableAddFooter(&cont,buf.data);
5209+
printTableAddFooter(&cont,buf.data);
5210+
}
5211+
PQclear(tabres);
52155212
}
5216-
PQclear(tabres);
52175213

52185214
printTable(&cont,pset.queryFout, false,pset.logfile);
52195215
printTableCleanup(&cont);

‎src/test/regress/expected/publication.out

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ ERROR: unrecognized publication parameter: foo
2121
CREATE PUBLICATION testpub_xxx WITH (publish = 'cluster, vacuum');
2222
ERROR: unrecognized "publish" value: "cluster"
2323
\dRp
24-
List of publications
25-
Name | Owner | Inserts | Updates | Deletes
26-
--------------------+--------------------------+---------+---------+---------
27-
testpib_ins_trunct | regress_publication_user | t | f | f
28-
testpub_default | regress_publication_user | f | t | f
24+
List of publications
25+
Name | Owner |All tables |Inserts | Updates | Deletes
26+
--------------------+--------------------------+------------+---------+---------+---------
27+
testpib_ins_trunct | regress_publication_user |f |t | f | f
28+
testpub_default | regress_publication_user | f | f| t | f
2929
(2 rows)
3030

3131
ALTER PUBLICATION testpub_default SET (publish = 'insert, update, delete');
3232
\dRp
33-
List of publications
34-
Name | Owner | Inserts | Updates | Deletes
35-
--------------------+--------------------------+---------+---------+---------
36-
testpib_ins_trunct | regress_publication_user | t | f | f
37-
testpub_default | regress_publication_user | t | t | t
33+
List of publications
34+
Name | Owner |All tables |Inserts | Updates | Deletes
35+
--------------------+--------------------------+------------+---------+---------+---------
36+
testpib_ins_trunct | regress_publication_user |f |t | f | f
37+
testpub_default | regress_publication_user |f |t | t | t
3838
(2 rows)
3939

4040
--- adding tables
@@ -75,26 +75,33 @@ Indexes:
7575
Publications:
7676
"testpub_foralltables"
7777

78+
\dRp+ testpub_foralltables
79+
Publication testpub_foralltables
80+
All tables | Inserts | Updates | Deletes
81+
------------+---------+---------+---------
82+
t | t | t | f
83+
(1 row)
84+
7885
DROP TABLE testpub_tbl2;
7986
DROP PUBLICATION testpub_foralltables;
8087
CREATE TABLE testpub_tbl3 (a int);
8188
CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
8289
CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
8390
CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
8491
\dRp+ testpub3
85-
Publication testpub3
86-
Inserts | Updates | Deletes
87-
---------+---------+---------
88-
t | t | t
92+
Publication testpub3
93+
All tables |Inserts | Updates | Deletes
94+
------------+---------+---------+---------
95+
f |t | t | t
8996
Tables:
9097
"public.testpub_tbl3"
9198
"public.testpub_tbl3a"
9299

93100
\dRp+ testpub4
94-
Publication testpub4
95-
Inserts | Updates | Deletes
96-
---------+---------+---------
97-
t | t | t
101+
Publication testpub4
102+
All tables |Inserts | Updates | Deletes
103+
------------+---------+---------+---------
104+
f |t | t | t
98105
Tables:
99106
"public.testpub_tbl3"
100107

@@ -112,10 +119,10 @@ ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl
112119
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1;
113120
ERROR: publication "testpub_fortbl" already exists
114121
\dRp+ testpub_fortbl
115-
Publication testpub_fortbl
116-
Inserts | Updates | Deletes
117-
---------+---------+---------
118-
t | t | t
122+
Publication testpub_fortbl
123+
All tables |Inserts | Updates | Deletes
124+
------------+---------+---------+---------
125+
f |t | t | t
119126
Tables:
120127
"pub_test.testpub_nopk"
121128
"public.testpub_tbl1"
@@ -158,10 +165,10 @@ Publications:
158165
"testpub_fortbl"
159166

160167
\dRp+ testpub_default
161-
Publication testpub_default
162-
Inserts | Updates | Deletes
163-
---------+---------+---------
164-
t | t | t
168+
Publication testpub_default
169+
All tables |Inserts | Updates | Deletes
170+
------------+---------+---------+---------
171+
f |t | t | t
165172
Tables:
166173
"pub_test.testpub_nopk"
167174
"public.testpub_tbl1"
@@ -203,10 +210,10 @@ DROP TABLE testpub_parted;
203210
DROP VIEW testpub_view;
204211
DROP TABLE testpub_tbl1;
205212
\dRp+ testpub_default
206-
Publication testpub_default
207-
Inserts | Updates | Deletes
208-
---------+---------+---------
209-
t | t | t
213+
Publication testpub_default
214+
All tables |Inserts | Updates | Deletes
215+
------------+---------+---------+---------
216+
f |t | t | t
210217
(1 row)
211218

212219
-- fail - must be owner of publication
@@ -216,20 +223,20 @@ ERROR: must be owner of publication testpub_default
216223
RESET ROLE;
217224
ALTER PUBLICATION testpub_default RENAME TO testpub_foo;
218225
\dRp testpub_foo
219-
List of publications
220-
Name | Owner | Inserts | Updates | Deletes
221-
-------------+--------------------------+---------+---------+---------
222-
testpub_foo | regress_publication_user | t | t | t
226+
List of publications
227+
Name | Owner |All tables |Inserts | Updates | Deletes
228+
-------------+--------------------------+------------+---------+---------+---------
229+
testpub_foo | regress_publication_user |f |t | t | t
223230
(1 row)
224231

225232
-- rename back to keep the rest simple
226233
ALTER PUBLICATION testpub_foo RENAME TO testpub_default;
227234
ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2;
228235
\dRp testpub_default
229-
List of publications
230-
Name | Owner | Inserts | Updates | Deletes
231-
-----------------+---------------------------+---------+---------+---------
232-
testpub_default | regress_publication_user2 | t | t | t
236+
List of publications
237+
Name | Owner |All tables |Inserts | Updates | Deletes
238+
-----------------+---------------------------+------------+---------+---------+---------
239+
testpub_default | regress_publication_user2 |f |t | t | t
233240
(1 row)
234241

235242
DROP PUBLICATION testpub_default;

‎src/test/regress/sql/publication.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ALTER PUBLICATION testpub_foralltables SET TABLE pub_test.testpub_nopk;
4545

4646
SELECT pubname, puballtablesFROM pg_publicationWHERE pubname='testpub_foralltables';
4747
\d+ testpub_tbl2
48+
\dRp+ testpub_foralltables
4849

4950
DROPTABLE testpub_tbl2;
5051
DROP PUBLICATION testpub_foralltables;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp