Show VIRTUAL keyword for virtual generated columns in pg_dump and psql

Started by Lakshmi N8 months ago3 messageshackers

Thread notes

1 note#feature#minor#enhancement
hackorum-bot#feature#minor#enhancement
hackorum-bot
1 day ago

@global #feature #minor #enhancement

#feature#minor#enhancement
Jump to latest
#1Lakshmi N
lakshmin.jhs@gmail.com

Hi,

Adding Peter and Dean based on the recent commit history for generated
columns.

pg_dump and psql's \d currently display stored and virtual generated
columns asymmetrically:

s_total integer GENERATED ALWAYS AS ((a + b)) STORED
v_total integer GENERATED ALWAYS AS ((a + b))

Since VIRTUAL is default most likely this was omitted but with this
puts the burden on the reader to identify whether it is STORED or
VIRTUAL since both kinds coexist in v19.

The attached patch adds the VIRTUAL keyword to the output of both
pg_dump and psql \d, so the display becomes:

s_total integer GENERATED ALWAYS AS ((a + b)) STORED
v_total integer GENERATED ALWAYS AS ((a + b)) VIRTUAL

The fix is three one-line changes:

- src/bin/pg_dump/pg_dump.c: append " VIRTUAL" instead of bare ")"
- src/bin/psql/describe.c: same for \d display
- src/bin/pg_dump/t/002_pg_dump.pl: update TAP test regex

The parser already accepts the VIRTUAL keyword, so pg_dump output
round-trips correctly (dump -> restore -> \d shows identical schema).
I verified this with a CTAS + dump + restore cycle.

Regards,
Lakshmi

Attachments:

show-virtual-keyword.patchapplication/octet-stream; name=show-virtual-keyword.patchDownload+129-99
#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Lakshmi N (#1)
Re: Show VIRTUAL keyword for virtual generated columns in pg_dump and psql

On Monday, April 13, 2026, Lakshmi N <lakshmin.jhs@gmail.com> wrote:

pg_dump and psql's \d currently display stored and virtual generated
columns asymmetrically:

s_total integer GENERATED ALWAYS AS ((a + b)) STORED
v_total integer GENERATED ALWAYS AS ((a + b))

Since VIRTUAL is default most likely this was omitted but with this

puts the burden on the reader to identify whether it is STORED or

VIRTUAL since both kinds coexist in v19.

The output follows existing conventions of not printing extraneous text.
Additionally, storage itself is non-standard so the absence of a modifier
is producing standard-compliant output. I would -1 changing pg_dump on
this basis. I’d be inclined to go with the symmetry/readability argument
for psql \d though.

David J.

#3Lakshmi N
lakshmin.jhs@gmail.com
In reply to: David G. Johnston (#2)
Re: Show VIRTUAL keyword for virtual generated columns in pg_dump and psql

Hi,

On Mon, Apr 13, 2026 at 5:27 AM David G. Johnston <
david.g.johnston@gmail.com> wrote:

On Monday, April 13, 2026, Lakshmi N <lakshmin.jhs@gmail.com> wrote:

pg_dump and psql's \d currently display stored and virtual generated
columns asymmetrically:

s_total integer GENERATED ALWAYS AS ((a + b)) STORED
v_total integer GENERATED ALWAYS AS ((a + b))

Since VIRTUAL is default most likely this was omitted but with this

puts the burden on the reader to identify whether it is STORED or

VIRTUAL since both kinds coexist in v19.

The output follows existing conventions of not printing extraneous text.
Additionally, storage itself is non-standard so the absence of a modifier
is producing standard-compliant output. I would -1 changing pg_dump on
this basis. I’d be inclined to go with the symmetry/readability argument
for psql \d though.

Thank you for the feedback! Updated the patch for psql \d only.

Regards,
Lakshmi

Attachments:

t139309_3
0001-Fix-psql-d-to-show-VIRTUAL-keyword-for-generated-col.patchapplication/octet-stream; name=0001-Fix-psql-d-to-show-VIRTUAL-keyword-for-generated-col.patchDownload+127-97