On 5/31/17 02:17, Kuntal Ghosh wrote:
> On Wed, May 31, 2017 at 12:58 AM, Masahiko Sawada <sawada.m...@gmail.com> 
> wrote:
>>
>> I'd say we can fix this issue by just changing the query. Attached
>> patch changes the query so that it can handle publication name
>> correctly, the query gets complex, though.
>>
> In is_publishable_class function, there are four conditions to decide
> whether this is a publishable class or not.
> 
> 1. relkind == RELKIND_RELATION
> 2. IsCatalogClass()
> 3. relpersistence == 'p'
> 4. relid >= FirstNormalObjectId /* Skip tables created during initdb */
> 
> I think the modified query should have a check for the fourth condition as 
> well.

The query should be fixed like in the attached patch.
pg_get_publication_tables() ends up calling is_publishable_class()
internally.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 4a93e9b8432661724e9fd400c8f267dd09d3b513 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@gmx.net>
Date: Wed, 31 May 2017 21:23:06 -0400
Subject: [PATCH] psql: Fix display of whether table is part of publication

If a FOR ALL TABLES publication was present, \d of a table would claim
for each table that it was part of the publication, even for tables that
are ignores, such as system tables and unlogged tables.  Fix the query
by using the function pg_get_publication_tables(), which was intended for
this purpose.

Reported-by: tushar <tushar.ah...@enterprisedb.com>
---
 src/bin/psql/describe.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 3e542f7b1d..f1c3d9b7e0 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -2537,10 +2537,9 @@ describeOneTableDetails(const char *schemaname,
                {
                        printfPQExpBuffer(&buf,
                                                          "SELECT pub.pubname\n"
-                                                         " FROM 
pg_catalog.pg_publication pub\n"
-                                                         " LEFT JOIN 
pg_catalog.pg_publication_rel pr\n"
-                                                         "      ON (pr.prpubid 
= pub.oid)\n"
-                                                         "WHERE pr.prrelid = 
'%s' OR pub.puballtables\n"
+                                                         " FROM 
pg_catalog.pg_publication pub,\n"
+                                                         "      
pg_catalog.pg_get_publication_tables(pub.pubname)\n"
+                                                         "WHERE relid = '%s'\n"
                                                          "ORDER BY 1;",
                                                          oid);
 
-- 
2.13.0

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to