Fix how some lists are displayed by psql \d+

Started by Peter Smith11 months ago16 messageshackers
Jump to latest
#1Peter Smith
smithpb2250@gmail.com

Hi.

I recently saw that the psql \d+ lists for "Partitions:" are not
aligned in quite the same way as other lists ("Publications:" etc)
because they use indents and line breaks differently. e.g. See below:

test_pub=# \d+ part1
Partitioned table "public.part1"
Column | Type | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
a | integer | | | | plain |
| |
Partition of: t1 FOR VALUES FROM (0) TO (50)
Partition constraint: ((a IS NOT NULL) AND (a >= 0) AND (a < 50))
Partition key: RANGE (a)
Publications:
"pub1"
"pub2"
"pub_only"
Partitions: part1_1 FOR VALUES FROM (0) TO (25), PARTITIONED,
part1_2 FOR VALUES FROM (25) TO (50)

~~~

PSA v1
0001 - Fix (common code) lists for "Partitions:" and "Child tables:"
0002 - Fix list for "Inherits:" in the same way

~~~

The *patched* result for the same example now looks like below. Notice
that in passing I also removed the comma separators, which are not
present in the other footer lists.

test_pub=# \d+ part1
Partitioned table "public.part1"
Column | Type | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
a | integer | | | | plain |
| |
Partition of: t1 FOR VALUES FROM (0) TO (50)
Partition constraint: ((a IS NOT NULL) AND (a >= 0) AND (a < 50))
Partition key: RANGE (a)
Publications:
"pub1"
"pub2"
"pub_only"
Partitions:
part1_1 FOR VALUES FROM (0) TO (25), PARTITIONED
part1_2 FOR VALUES FROM (25) TO (50)

======
Kind Regards,
Peter Smith.
Fujitsu Australia

Attachments:

v1-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patchapplication/octet-stream; name=v1-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patchDownload+218-130
v1-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patchapplication/octet-stream; name=v1-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patchDownload+157-105
#2Chao Li
li.evan.chao@gmail.com
In reply to: Peter Smith (#1)
Re: Fix how some lists are displayed by psql \d+

On Jan 9, 2026, at 06:47, Peter Smith <smithpb2250@gmail.com> wrote:

Hi.

I recently saw that the psql \d+ lists for "Partitions:" are not
aligned in quite the same way as other lists ("Publications:" etc)
because they use indents and line breaks differently. e.g. See below:

test_pub=# \d+ part1
Partitioned table "public.part1"
Column | Type | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
a | integer | | | | plain |
| |
Partition of: t1 FOR VALUES FROM (0) TO (50)
Partition constraint: ((a IS NOT NULL) AND (a >= 0) AND (a < 50))
Partition key: RANGE (a)
Publications:
"pub1"
"pub2"
"pub_only"
Partitions: part1_1 FOR VALUES FROM (0) TO (25), PARTITIONED,
part1_2 FOR VALUES FROM (25) TO (50)

~~~

PSA v1
0001 - Fix (common code) lists for "Partitions:" and "Child tables:"
0002 - Fix list for "Inherits:" in the same way

~~~

The *patched* result for the same example now looks like below. Notice
that in passing I also removed the comma separators, which are not
present in the other footer lists.

test_pub=# \d+ part1
Partitioned table "public.part1"
Column | Type | Collation | Nullable | Default | Storage |
Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
a | integer | | | | plain |
| |
Partition of: t1 FOR VALUES FROM (0) TO (50)
Partition constraint: ((a IS NOT NULL) AND (a >= 0) AND (a < 50))
Partition key: RANGE (a)
Publications:
"pub1"
"pub2"
"pub_only"
Partitions:
part1_1 FOR VALUES FROM (0) TO (25), PARTITIONED
part1_2 FOR VALUES FROM (25) TO (50)

======
Kind Regards,
Peter Smith.
Fujitsu Australia
<v1-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patch><v1-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patch>

This is a simple change, but makes sense to me, making the display looking better.

The code change is straightforward and LGTM.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#3Neil Chen
carpenter.nail.cz@gmail.com
In reply to: Peter Smith (#1)
Re: Fix how some lists are displayed by psql \d+

Hi Peter,

On Fri, Jan 9, 2026 at 6:47 AM Peter Smith <smithpb2250@gmail.com> wrote:

I recently saw that the psql \d+ lists for "Partitions:" are not
aligned in quite the same way as other lists ("Publications:" etc)
because they use indents and line breaks differently. e.g. See below:

PSA v1
0001 - Fix (common code) lists for "Partitions:" and "Child tables:"
0002 - Fix list for "Inherits:" in the same way

This patch looks good to me.
However, referring to the original code implementation, I believe the
initial design intention for the psql display was to make it as "compact"
as possible.
I'm not sure.. if it's worthwhile to uniformly change the display style of
other items you mentioned (such as Publications) to the compact style?

#4Peter Smith
smithpb2250@gmail.com
In reply to: Neil Chen (#3)
Re: Fix how some lists are displayed by psql \d+

On Fri, Jan 9, 2026 at 12:19 PM Neil Chen <carpenter.nail.cz@gmail.com> wrote:

...

This patch looks good to me.
However, referring to the original code implementation, I believe the initial design intention for the psql display was to make it as "compact" as possible.
I'm not sure.. if it's worthwhile to uniformly change the display style of other items you mentioned (such as Publications) to the compact style?

Hi Neil.

Thanks for the review and the feedback.

I assume the "compactness" you are referring to is where the first
item was appearing on the same line as the list header "Partitions:".
Yes, I did recognize and consider doing the same for all lists, but it
seemed more work, and the end result would *still* have mis-aligned
lists whenever there are multiple list types (because those list
headers are of all different lengths so the indents are different).
IMO that mis-alignment would still look messy just as the current HEAD
does.

TBH, I don't know if the primary goal of the \d+ is compactness, or
readability. I chose readability. YMMV.

There might be some middle ground, where lists having just a single
item can appear on the same line as their list header. But, with lots
of different kinds of lists, all that extra compacting logic seems
overkill to me just for the sake of 1 or 2 fewer lines in the \d+
output. Again, that's why I chose the KISS approach.

Waiting for other opinions.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

#5Greg Sabino Mullane
htamfids@gmail.com
In reply to: Peter Smith (#4)
Re: Fix how some lists are displayed by psql \d+

Patch looks good to me, and +1 for consistency and readability versus
saving a newline (but adding commas!)

Cheers,
Greg

#6Peter Smith
smithpb2250@gmail.com
In reply to: Peter Smith (#1)
Re: Fix how some lists are displayed by psql \d+

Ping. This small patch had received a couple of LGTM, but then the
thread went silent for nearly 2 weeks.

I've created a new CF entry [1]https://commitfest.postgresql.org/patch/6413/ marked "ready for committer". Is there
anything else I can do to help get this one over the line?

======
[1]: https://commitfest.postgresql.org/patch/6413/

Kind Regards,
Peter Smith.
Fujitsu Australia

#7Peter Smith
smithpb2250@gmail.com
In reply to: Peter Smith (#1)
Re: Fix how some lists are displayed by psql \d+

A rebase was needed for some more test expected output changes.

PSA v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

Attachments:

v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patchapplication/octet-stream; name=v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patchDownload+218-130
v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patchapplication/octet-stream; name=v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patchDownload+160-107
#8Chao Li
li.evan.chao@gmail.com
In reply to: Peter Smith (#7)
Re: Fix how some lists are displayed by psql \d+

On Jan 21, 2026, at 10:58, Peter Smith <smithpb2250@gmail.com> wrote:

A rebase was needed for some more test expected output changes.

PSA v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia
<v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patch><v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patch>

I still see some difference:
```
evantest=# \d+ p_test;
Partitioned table "public.p_test"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
----------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
id | integer | | | | plain | | |
username | text | | | | extended | | |
category | text | | | | extended | | |
Partition key: LIST (category)
Indexes:
"idx_p_test_id" btree (id)
Partitions:
p_test_v1 FOR VALUES IN ('A')
p_test_v2 FOR VALUES IN ('B')
```

The index name is quoted, but the partition names are not.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#9Peter Smith
smithpb2250@gmail.com
In reply to: Chao Li (#8)
Re: Fix how some lists are displayed by psql \d+

On Wed, Jan 21, 2026 at 7:05 PM Chao Li <li.evan.chao@gmail.com> wrote:

On Jan 21, 2026, at 10:58, Peter Smith <smithpb2250@gmail.com> wrote:

A rebase was needed for some more test expected output changes.

PSA v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia
<v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patch><v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patch>

I still see some difference:
```
evantest=# \d+ p_test;
Partitioned table "public.p_test"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
----------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
id | integer | | | | plain | | |
username | text | | | | extended | | |
category | text | | | | extended | | |
Partition key: LIST (category)
Indexes:
"idx_p_test_id" btree (id)
Partitions:
p_test_v1 FOR VALUES IN ('A')
p_test_v2 FOR VALUES IN ('B')
```

The index name is quoted, but the partition names are not.

AFAICT
Indexes are quoted
Constraints are quoted
Publications are also quoted

Partitions are NOT quoted
Inherits are NOT quoted

~

Please confirm --- So, you are expecting that Partitions and Child
tables should also be quoted, so that everything looks the same?

This is scope creep from the original intent of this thread, so I will
look at doing this in a separate patch 0003.

======
Kind Regards
Peter Smith.
Fujitsu Australia

#10Chao Li
li.evan.chao@gmail.com
In reply to: Peter Smith (#9)
Re: Fix how some lists are displayed by psql \d+

On Jan 21, 2026, at 16:22, Peter Smith <smithpb2250@gmail.com> wrote:

On Wed, Jan 21, 2026 at 7:05 PM Chao Li <li.evan.chao@gmail.com> wrote:

On Jan 21, 2026, at 10:58, Peter Smith <smithpb2250@gmail.com> wrote:

A rebase was needed for some more test expected output changes.

PSA v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia
<v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patch><v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patch>

I still see some difference:
```
evantest=# \d+ p_test;
Partitioned table "public.p_test"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
----------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
id | integer | | | | plain | | |
username | text | | | | extended | | |
category | text | | | | extended | | |
Partition key: LIST (category)
Indexes:
"idx_p_test_id" btree (id)
Partitions:
p_test_v1 FOR VALUES IN ('A')
p_test_v2 FOR VALUES IN ('B')
```

The index name is quoted, but the partition names are not.

AFAICT
Indexes are quoted
Constraints are quoted
Publications are also quoted

Partitions are NOT quoted
Inherits are NOT quoted

~

Please confirm --- So, you are expecting that Partitions and Child
tables should also be quoted, so that everything looks the same?

This is scope creep from the original intent of this thread, so I will
look at doing this in a separate patch 0003.

======
Kind Regards
Peter Smith.
Fujitsu Australia

Actually I don’t know the rule, which should be quoted and which should not. Is the inconstancy a blocker?

So, I was just pointing out the inconsistency, and I want to hear a clarification from someone.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#11Peter Smith
smithpb2250@gmail.com
In reply to: Chao Li (#10)
Re: Fix how some lists are displayed by psql \d+

On Wed, Jan 21, 2026 at 7:30 PM Chao Li <li.evan.chao@gmail.com> wrote:

On Jan 21, 2026, at 16:22, Peter Smith <smithpb2250@gmail.com> wrote:

On Wed, Jan 21, 2026 at 7:05 PM Chao Li <li.evan.chao@gmail.com> wrote:

On Jan 21, 2026, at 10:58, Peter Smith <smithpb2250@gmail.com> wrote:

A rebase was needed for some more test expected output changes.

PSA v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia
<v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patch><v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patch>

I still see some difference:
```
evantest=# \d+ p_test;
Partitioned table "public.p_test"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
----------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
id | integer | | | | plain | | |
username | text | | | | extended | | |
category | text | | | | extended | | |
Partition key: LIST (category)
Indexes:
"idx_p_test_id" btree (id)
Partitions:
p_test_v1 FOR VALUES IN ('A')
p_test_v2 FOR VALUES IN ('B')
```

The index name is quoted, but the partition names are not.

AFAICT
Indexes are quoted
Constraints are quoted
Publications are also quoted

Partitions are NOT quoted
Inherits are NOT quoted

~

Please confirm --- So, you are expecting that Partitions and Child
tables should also be quoted, so that everything looks the same?

This is scope creep from the original intent of this thread, so I will
look at doing this in a separate patch 0003.

======
Kind Regards
Peter Smith.
Fujitsu Australia

Actually I don’t know the rule, which should be quoted and which should not. Is the inconstancy a blocker?

So, I was just pointing out the inconsistency, and I want to hear a clarification from someone.

OK. I feel that the "Partitions" and "Child tables" + "Interits" might
be the odd ones out here, just as those were the odd ones out re the
list indentation logic.

But I will hold off on adding quotes for them until I hear some
committer advice that it would be a worthwhile change.

======
Kind Regards,
Peter Smith.
Fujitsu Australia

#12Soumya S Murali
soumyamurali.work@gmail.com
In reply to: Peter Smith (#11)
Re: Fix how some lists are displayed by psql \d+

Hi all,

Thank you for updating the patches.

On Tue, Feb 3, 2026 at 3:24 PM Peter Smith <smithpb2250@gmail.com> wrote:

On Wed, Jan 21, 2026 at 7:30 PM Chao Li <li.evan.chao@gmail.com> wrote:

On Jan 21, 2026, at 16:22, Peter Smith <smithpb2250@gmail.com> wrote:

On Wed, Jan 21, 2026 at 7:05 PM Chao Li <li.evan.chao@gmail.com> wrote:

On Jan 21, 2026, at 10:58, Peter Smith <smithpb2250@gmail.com> wrote:

A rebase was needed for some more test expected output changes.

PSA v2.

======
Kind Regards,
Peter Smith.
Fujitsu Australia
<v2-0002-Fix-to-make-psql-d-lists-of-inherits-look-same-as.patch><v2-0001-Fix-to-make-psql-d-lists-of-partitions-look-same-.patch>

I still see some difference:
```
evantest=# \d+ p_test;
Partitioned table "public.p_test"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
----------+---------+-----------+----------+---------+----------+-------------+--------------+-------------
id | integer | | | | plain | | |
username | text | | | | extended | | |
category | text | | | | extended | | |
Partition key: LIST (category)
Indexes:
"idx_p_test_id" btree (id)
Partitions:
p_test_v1 FOR VALUES IN ('A')
p_test_v2 FOR VALUES IN ('B')
```

The index name is quoted, but the partition names are not.

AFAICT
Indexes are quoted
Constraints are quoted
Publications are also quoted

Partitions are NOT quoted
Inherits are NOT quoted

~

Please confirm --- So, you are expecting that Partitions and Child
tables should also be quoted, so that everything looks the same?

This is scope creep from the original intent of this thread, so I will
look at doing this in a separate patch 0003.

======
Kind Regards
Peter Smith.
Fujitsu Australia

Actually I don’t know the rule, which should be quoted and which should not. Is the inconstancy a blocker?

So, I was just pointing out the inconsistency, and I want to hear a clarification from someone.

OK. I feel that the "Partitions" and "Child tables" + "Interits" might
be the odd ones out here, just as those were the odd ones out re the
list indentation logic.

But I will hold off on adding quotes for them until I hear some
committer advice that it would be a worthwhile change.

I went through the discussions and verified the unpatched psql display
and after tested the v2 patches on the current master. The patches
applied cleanly, make check and tests passed successfully and using
the patches confirms that "Partitions" and "Child tables" are now
displayed consistently as intended. LGTM from my side.

Regards,
Soumya

#13Peter Smith
smithpb2250@gmail.com
In reply to: Soumya S Murali (#12)
Re: Fix how some lists are displayed by psql \d+

Ping, This thread has been idle for about 6 weeks but AFAIK the patch
is good to go.

Is there any else I can do to help move it forwards?

======
Kind Regards,
Peter Smith.
Fujitsu Australia

#14Fujii Masao
masao.fujii@gmail.com
In reply to: Peter Smith (#13)
Re: Fix how some lists are displayed by psql \d+

On Fri, Mar 20, 2026 at 12:49 PM Peter Smith <smithpb2250@gmail.com> wrote:

Ping, This thread has been idle for about 6 weeks but AFAIK the patch
is good to go.

Is there any else I can do to help move it forwards?

I like the updated \d+ display. The patch looks good to me.
So, barring objections, I'm thinking to commit it.

BTW, with these changes there appear to be no remaining callers of
pg_wcswidth() in the core. I'm not sure if we should remove it,
or keep it for reference or potential external use, though.

Regards,

--
Fujii Masao

#15Fujii Masao
masao.fujii@gmail.com
In reply to: Fujii Masao (#14)
Re: Fix how some lists are displayed by psql \d+

On Thu, Mar 26, 2026 at 12:18 PM Fujii Masao <masao.fujii@gmail.com> wrote:

On Fri, Mar 20, 2026 at 12:49 PM Peter Smith <smithpb2250@gmail.com> wrote:

Ping, This thread has been idle for about 6 weeks but AFAIK the patch
is good to go.

Is there any else I can do to help move it forwards?

I like the updated \d+ display. The patch looks good to me.
So, barring objections, I'm thinking to commit it.

I've pushed the patches. Thanks!

Regards,

--
Fujii Masao

#16Peter Smith
smithpb2250@gmail.com
In reply to: Fujii Masao (#15)
Re: Fix how some lists are displayed by psql \d+

On Mon, Mar 30, 2026 at 1:23 PM Fujii Masao <masao.fujii@gmail.com> wrote:

On Thu, Mar 26, 2026 at 12:18 PM Fujii Masao <masao.fujii@gmail.com> wrote:

On Fri, Mar 20, 2026 at 12:49 PM Peter Smith <smithpb2250@gmail.com> wrote:

Ping, This thread has been idle for about 6 weeks but AFAIK the patch
is good to go.

Is there any else I can do to help move it forwards?

I like the updated \d+ display. The patch looks good to me.
So, barring objections, I'm thinking to commit it.

I've pushed the patches. Thanks!

Thanks for pushing!

======
Kind Regards,
Peter Smith.
Fujitsu Australia