Inconsistency in psql output with \d+x PATTERN

From: George MacKerron <george(dot)mackerron(at)databricks(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Inconsistency in psql output with \d+x PATTERN
Date: 2026-10-16 14:35:33
Message-ID: FEA91EA9-CF32-4920-9674-F2C3E01C3807@databricks.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello.

While working on https://github.com/neondatabase/psql-describe, I came across what I think is minor bug in the output of psql’s `\d` with a pattern or name.

Using psql 19rc1, this command is not listed by `\?` as accepting the expanded (x) option:

```
db=# \?
...
Informational
(options: S = show system objects, x = expanded mode, + = additional detail)
\d[Sx+] list tables, views, and sequences
\d[S+] NAME describe table, view, sequence, or index
```

And, in general, setting the x option -- either globally with `\x on` or temporarily with `\d+x PATTERN` -- is ignored.

However, it is not ignored when describing sequences. For example:

```
db=# create table example_table (col int);
CREATE TABLE
db=# create sequence example_sequence;
CREATE SEQUENCE
db=# create index example_idx on example_table(col);
CREATE INDEX
db=# \d+x example_*
Index "public.example_idx"
Column | Type | Key? | Definition | Storage | Stats target
--------+---------+------+------------+---------+--------------
col | integer | yes | col | plain |
btree, for table "public.example_table"

Sequence "public.example_sequence"
-[ RECORD 1 ]------------------
Type | bigint
Start | 1
Minimum | 1
Maximum | 9223372036854775807
Increment | 1
Cycles? | no
Cache | 1

Table "public.example_table"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
col | integer | | | | plain | | |
Indexes:
"example_idx" btree (col)
Access method: heap

```

This inconsistency seems like a bug to me.

Proximately, the bug appears to arise on line 1780 of src/bin/psql/describe.c (REL_19_RC1), where a new, shadowing `myopt` variable is created without setting `myopt.topt.expanded = false`.

History:

• In 2005, commit 3332e38189b2 disables expanded output for \d NAME.
• In 2017, commit 2a14b9609df1 redesigns sequence descriptions as a separate query and (presumably unintentionally) bypasses that disabling.
• In 2025, commit 00f4c2959d6 adds the temporary x modifier. Its regression test explicitly verifies that \d+x table remains non-expanded, but does not test a sequence.

All the best,
George

Browse pgsql-bugs by date

  From Date Subject
Next Message Nitin Motiani 2026-10-16 14:43:59 Re: BUG #19765: Wrong result from a chain of LEFT JOINs since v16
Previous Message Staroverov Ilja 2026-10-16 13:18:39 Re: [MASSMAIL] pg_stat_statements replaces SQL/JSON ON EMPTY / ON ERROR keywords with parameters