Обсуждение: Fix how some lists are displayed by psql \d+

Поиск
Список
Период
Сортировка

Fix how some lists are displayed by psql \d+

От
Peter Smith
Дата:
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

Вложения

Re: Fix how some lists are displayed by psql \d+

От
Chao Li
Дата:

> 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/







Re: Fix how some lists are displayed by psql \d+

От
Neil Chen
Дата:
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?

Re: Fix how some lists are displayed by psql \d+

От
Peter Smith
Дата:
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
wasto 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



Re: Fix how some lists are displayed by psql \d+

От
Greg Sabino Mullane
Дата:
Patch looks good to me, and +1 for consistency and readability versus saving a newline (but adding commas!)

Cheers,
Greg

Re: Fix how some lists are displayed by psql \d+

От
Peter Smith
Дата:
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] 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



Re: Fix how some lists are displayed by psql \d+

От
Peter Smith
Дата:
A rebase was needed for some more test expected output changes.

PSA v2.

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

Вложения

Re: Fix how some lists are displayed by psql \d+

От
Chao Li
Дата:

> 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/







Re: Fix how some lists are displayed by psql \d+

От
Peter Smith
Дата:
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



Re: Fix how some lists are displayed by psql \d+

От
Chao Li
Дата:

> 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/







Re: Fix how some lists are displayed by psql \d+

От
Peter Smith
Дата:
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



Re: Fix how some lists are displayed by psql \d+

От
Soumya S Murali
Дата:
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