Re: PSQL - prevent describe listing tables that are already in listed schemas

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: PSQL - prevent describe listing tables that are already in listed schemas
Date: 2026-05-19 12:08:36
Message-ID: 1b1c88ce-2c61-4faf-b647-496525fc177f@uni-muenster.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
v3-0001-Fix-psql-publication-describe-for-tables-in-schem.patch text/x-patch 3.0 KB
v3-0002-Fix-publication-duplication-in-table-decription.patch text/x-patch 1.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2026-05-19 13:00:58 Re: Function scan FDW pushdown
Previous Message Nisha Moond 2026-05-19 11:14:09 Re: Support EXCEPT for TABLES IN SCHEMA publications