| From: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
|---|---|
| To: | Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Show comments in \dRp+, \dRs+, and \dX+ psql meta-commands |
| Date: | 2026-02-20 09:29:07 |
| Message-ID: | 82b25785-0dc1-46d6-93ac-ce385a3a0bfc@uni-muenster.de |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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 | Content-Type | Size |
|---|---|---|
| v2-0001-Show-comments-in-dRp-dRs-and-dX-psql-meta-command.patch | text/x-patch | 138.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ajit Awekar | 2026-02-20 09:42:10 | Re: [OAuth2] Infrastructure for tracking token expiry time |
| Previous Message | Nitin Motiani | 2026-02-20 09:08:17 | Re: Adding pg_dump flag for parallel export to pipes |