Re: Show comments in \dRp+, \dRs+, and \dX+ psql meta-commands - Mailing list pgsql-hackers

From Jim Jones
Subject Re: Show comments in \dRp+, \dRs+, and \dX+ psql meta-commands
Date
Msg-id 82b25785-0dc1-46d6-93ac-ce385a3a0bfc@uni-muenster.de
Whole thread Raw
In response to Show comments in \dRp+, \dRs+, and \dX+ psql meta-commands  (Fujii Masao <masao.fujii@gmail.com>)
Responses Re: Show comments in \dRp+, \dRs+, and \dX+ psql meta-commands
List pgsql-hackers
Hi Fujii,

Due to recent changes in describe.c and subscription.out, v1 was no
longer applying. I rebased it just to test the feature -- feel free to
revert it.

v2 attached.

On 16/02/2026 15:57, Fujii Masao wrote:
> The psql meta-commands that list publications, subscriptions, and extended
> statistics (\dRp+, \dRs+, and \dX+) do not display their associated comments,
> whereas other \d meta-commands do. This makes it inconvenient to view
> these objects together with their descriptions.
> 
> I'd like to propose the attached patch to improve \dRp+ and \dRs+ so
> they include comments for publications and subscriptions. The patch also
> extends the \dX meta-command to accept the + option, allowing comments
> for extended statistics to be shown when requested. Thoughts?

The feature LGTM!
Here some tests:

postgres=# \pset null '(null)'
Null display is "(null)".

## Statistics

CREATE TABLE t (a int, b int);
CREATE STATISTICS stat1 (dependencies) ON a, b FROM t;
COMMENT ON STATISTICS stat1 IS 'stat 🐘 comment';
CREATE STATISTICS stat2 (dependencies) ON b, a FROM t;
COMMENT ON STATISTICS stat2 IS NULL;

postgres=# \dX+
List of extended statistics
-[ RECORD 1 ]+----------------
Schema       | public
Name         | stat1
Definition   | a, b FROM t
Ndistinct    | (null)
Dependencies | defined
MCV          | (null)
Description  | stat 🐘 comment
-[ RECORD 2 ]+----------------
Schema       | public
Name         | stat2
Definition   | a, b FROM t
Ndistinct    | (null)
Dependencies | defined
MCV          | (null)
Description  | (null)

## Publications

CREATE PUBLICATION pub FOR TABLE t;
COMMENT ON PUBLICATION pub IS E'pub \n comment';

postgres=# \dRp+
Publication pub
-[ RECORD 1 ]-----+---------
Owner             | jim
All tables        | f
All sequences     | f
Inserts           | t
Updates           | t
Deletes           | t
Truncates         | t
Generated columns | none
Via root          | f
Description       | pub     +
                  |  comment

Tables:
    "public.t"

## Subscriptions

CREATE SUBSCRIPTION sub
CONNECTION 'dbname=postgres'
PUBLICATION pub
WITH (connect = false);
COMMENT ON SUBSCRIPTION sub IS E'sub \"\'comment';

postgres=# \dRs+
List of subscriptions
-[ RECORD 1 ]----------+----------------
Name                   | sub
Owner                  | jim
Enabled                | f
Publication            | {pub}
Binary                 | f
Streaming              | parallel
Two-phase commit       | d
Disable on error       | f
Origin                 | any
Password required      | t
Run as owner?          | f
Failover               | f
Retain dead tuples     | f
Max retention duration | 0
Retention active       | f
Synchronous commit     | off
Conninfo               | dbname=postgres
Receiver timeout       | -1
Skip LSN               | 0/00000000
Description            | sub "'comment

The comments are displayed as expected.

One unrelated thing caught my attention though: NULLs and empty strings
are both displayed as NULL, which is expected according to
CreateComments() in comment.c

...
/* Reduce empty-string to NULL case */
if (comment != NULL && strlen(comment) == 0)
  comment = NULL;
...

However, I couldn't find anything in the docs that clearly says that
it's going to be the case -- at least not in comment.sgml.

CREATE SEQUENCE s1;
COMMENT ON SEQUENCE s1 IS '';
CREATE SEQUENCE s2;
COMMENT ON SEQUENCE s2 IS NULL;

postgres=# \ds+
List of sequences
-[ RECORD 1 ]-----------
Schema      | public
Name        | s1
Type        | sequence
Owner       | jim
Persistence | permanent
Size        | 8192 bytes
Description | (null)
-[ RECORD 2 ]-----------
Schema      | public
Name        | s2
Type        | sequence
Owner       | jim
Persistence | permanent
Size        | 8192 bytes
Description | (null)

Is it perhaps an undocumented behaviour?

Best, Jim

Attachment

pgsql-hackers by date:

Previous
From: Nitin Motiani
Date:
Subject: Re: Adding pg_dump flag for parallel export to pipes
Next
From: Ajit Awekar
Date:
Subject: Re: [OAuth2] Infrastructure for tracking token expiry time