Skip to content

Postgres: Accept generated columns with no mode keyword or VIRTUAL - #2441

Draft
ting-hong-shieh wants to merge 1 commit into
apache:mainfrom
ting-hong-shieh:postgres-generated-column-mode
Draft

Postgres: Accept generated columns with no mode keyword or VIRTUAL#2441
ting-hong-shieh wants to merge 1 commit into
apache:mainfrom
ting-hong-shieh:postgres-generated-column-mode

Conversation

@ting-hong-shieh

Copy link
Copy Markdown

Fixes #2407.

PostgreSqlDialect required STORED after GENERATED ALWAYS AS (expr), so it rejected both the omitted mode and an explicit VIRTUAL:

CREATE TABLE users (..., name character varying(255)
    GENERATED ALWAYS AS (((first_name || ' '::text) || last_name)) NOT NULL);
-- Expected: STORED, found: NOT at Line: 6, Column: 9

CREATE TABLE users (a text, name text GENERATED ALWAYS AS (a) VIRTUAL);
-- Expected: STORED, found: VIRTUAL at Line: 1, Column: 63

PostgreSQL 18 documents the grammar as GENERATED ALWAYS AS ( generation_expr ) [ STORED | VIRTUAL ], with VIRTUAL as the default when the keyword is omitted.

This removes the PostgreSqlDialect special case so the dialect falls back to the shared handling, which already parses both forms and round-trips them unchanged. STORED is unaffected.

PostgreSqlDialect required STORED after GENERATED ALWAYS AS (expr), so it
rejected both the omitted mode and an explicit VIRTUAL.

PostgreSQL 18 documents the grammar as
GENERATED ALWAYS AS ( generation_expr ) [ STORED | VIRTUAL ], with VIRTUAL as
the default when the keyword is omitted.

Remove the PostgreSqlDialect special case so the dialect falls back to the
shared handling, which parses both forms and round-trips them unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL 18 generated virtual columns require STORED

1 participant