Fix how some lists are displayed by psql \d+

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

Fix how some lists are displayed by psql \d+

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

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

От:
Chao Li <li.evan.chao@gmail.com>
Дата:


> On Jan 9, 2026, at 06:47, Peter Smith  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
> 


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 <carpenter.nail.cz@gmail.com>
Дата:
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 <smithpb2250@gmail.com>
Дата:
On Fri, Jan 9, 2026 at 12:19 PM Neil Chen  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


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

От:
Greg Sabino Mullane <htamfids@gmail.com>
Дата:
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 <smithpb2250@gmail.com>
Дата:
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 <smithpb2250@gmail.com>
Дата:
Вложения:
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 <li.evan.chao@gmail.com>
Дата:


> On Jan 21, 2026, at 10:58, Peter Smith  wrote:
> 
> A rebase was needed for some more test expected output changes.
> 
> PSA v2.
> 
> ======
> Kind Regards,
> Peter Smith.
> Fujitsu Australia
> 

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 <smithpb2250@gmail.com>
Дата:
On Wed, Jan 21, 2026 at 7:05 PM Chao Li  wrote:
>
>
>
> > On Jan 21, 2026, at 10:58, Peter Smith  wrote:
> >
> > A rebase was needed for some more test expected output changes.
> >
> > PSA v2.
> >
> > ======
> > Kind Regards,
> > Peter Smith.
> > Fujitsu Australia
> > 
>
> 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 <li.evan.chao@gmail.com>
Дата:


> On Jan 21, 2026, at 16:22, Peter Smith  wrote:
> 
> On Wed, Jan 21, 2026 at 7:05 PM Chao Li  wrote:
>> 
>> 
>> 
>>> On Jan 21, 2026, at 10:58, Peter Smith  wrote:
>>> 
>>> A rebase was needed for some more test expected output changes.
>>> 
>>> PSA v2.
>>> 
>>> ======
>>> Kind Regards,
>>> Peter Smith.
>>> Fujitsu Australia
>>> 
>> 
>> 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 <smithpb2250@gmail.com>
Дата:
On Wed, Jan 21, 2026 at 7:30 PM Chao Li  wrote:
>
>
>
> > On Jan 21, 2026, at 16:22, Peter Smith  wrote:
> >
> > On Wed, Jan 21, 2026 at 7:05 PM Chao Li  wrote:
> >>
> >>
> >>
> >>> On Jan 21, 2026, at 10:58, Peter Smith  wrote:
> >>>
> >>> A rebase was needed for some more test expected output changes.
> >>>
> >>> PSA v2.
> >>>
> >>> ======
> >>> Kind Regards,
> >>> Peter Smith.
> >>> Fujitsu Australia
> >>> 
> >>
> >> 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 <soumyamurali.work@gmail.com>
Дата:
Hi all,

Thank you for updating the patches.

On Tue, Feb 3, 2026 at 3:24 PM Peter Smith  wrote:
>
> On Wed, Jan 21, 2026 at 7:30 PM Chao Li  wrote:
> >
> >
> >
> > > On Jan 21, 2026, at 16:22, Peter Smith  wrote:
> > >
> > > On Wed, Jan 21, 2026 at 7:05 PM Chao Li  wrote:
> > >>
> > >>
> > >>
> > >>> On Jan 21, 2026, at 10:58, Peter Smith  wrote:
> > >>>
> > >>> A rebase was needed for some more test expected output changes.
> > >>>
> > >>> PSA v2.
> > >>>
> > >>> ======
> > >>> Kind Regards,
> > >>> Peter Smith.
> > >>> Fujitsu Australia
> > >>> 
> > >>
> > >> 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


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

От:
Peter Smith <smithpb2250@gmail.com>
Дата:
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


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

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Mar 20, 2026 at 12:49 PM Peter Smith  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


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

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Mar 26, 2026 at 12:18 PM Fujii Masao  wrote:
>
> On Fri, Mar 20, 2026 at 12:49 PM Peter Smith  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


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

От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Mon, Mar 30, 2026 at 1:23 PM Fujii Masao  wrote:
>
> On Thu, Mar 26, 2026 at 12:18 PM Fujii Masao  wrote:
> >
> > On Fri, Mar 20, 2026 at 12:49 PM Peter Smith  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


FAQ