Re: PSQL - prevent describe listing tables that are already in listed schemas - Mailing list pgsql-hackers

From Jim Jones
Subject Re: PSQL - prevent describe listing tables that are already in listed schemas
Date
Msg-id 1b1c88ce-2c61-4faf-b647-496525fc177f@uni-muenster.de
Whole thread
In response to Re: PSQL - prevent describe listing tables that are already in listed schemas  (Peter Smith <smithpb2250@gmail.com>)
List pgsql-hackers
On 19/05/2026 09:08, Peter Smith wrote:
> Thanks for reviewing and testing my patch. PSA v2 with that missing \n restored.

LGTM.

In the same light, we might also want to take a look at \d+. Currently
it can display the publication twice:

postgres=# \d+ s.t2
                                              Table "s.t2"
 Column |  Type   | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 c      | integer |           |          |         | plain   |
  |              |
Included in publications:
    "pub1" WHERE (c > 42)
    "pub1"
Access method: heap


Adding a similar logic to describeOneTableDetails might do the trick:

"  AND NOT EXISTS (\n"
"     SELECT 1\n"
"     FROM pg_catalog.pg_publication_namespace pn\n"
"     WHERE pn.pnpubid = p.oid\n"
"       AND pn.pnnspid = c.relnamespace)\n",

==============

Example:

postgres=# CREATE SCHEMA s;
CREATE TABLE public.t1(c int);
CREATE TABLE s.t2(c int);
CREATE TABLE s.t3(c int);
CREATE TABLE s.t4(c int);
CREATE PUBLICATION pub1 FOR
  TABLES IN SCHEMA s,
  TABLE s.t3, s.t4,
        s.t2 WHERE (c > 42),
        public.t1;

postgres=# \d+ s.t2
                                              Table "s.t2"
 Column |  Type   | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 c      | integer |           |          |         | plain   |
  |              |
Included in publications:
    "pub1"
Access method: heap

postgres=# CREATE PUBLICATION pub2 FOR TABLE s.t2;
CREATE PUBLICATION
postgres=# \d+ s.t2
                                              Table "s.t2"
 Column |  Type   | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 c      | integer |           |          |         | plain   |
  |              |
Included in publications:
    "pub1"
    "pub2"
Access method: heap

postgres=# \d+ s.t3
                                              Table "s.t3"
 Column |  Type   | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 c      | integer |           |          |         | plain   |
  |              |
Included in publications:
    "pub1"
Access method: heap

postgres=# \d public.t1
                 Table "public.t1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 c      | integer |           |          |
Included in publications:
    "pub1"


What do you think?
PSA a POC in v3-0002.

Best, Jim

Attachment

pgsql-hackers by date:

Previous
From: Nisha Moond
Date:
Subject: Re: Support EXCEPT for TABLES IN SCHEMA publications
Next
From: Alexander Korotkov
Date:
Subject: Re: Function scan FDW pushdown