Skip to content

[BUG] Wrong statement when using generated always as #212

Open

Description

@VincentCordobes

Describe the bug

When I pg-schema-diff apply after adding this column:

search_vector tsvector generated always as (
  to_tsvector('simple', title || ' ' || coalesce(artist, ''))
) stored

I get the following error:

Error: generating plan: validating migration plan: running migration plan: executing migration statement: {ALTER TABLE "public"."tabs" ADD COLUMN "search_vector" tsvector DEFAULT to_tsvector('simple'::regconfig, ((title || ' '::text) || COALESCE(artist, ''::text))) 3s 3s []}: ERROR: cannot use column reference in DEFAULT expression (SQLSTATE 0A000) 
diff.Plan{
    Statements: {
        {
            DDL:         "ALTER TABLE \"public\".\"tabs\" ADD COLUMN \"search_vector\" tsvector DEFAULT to_tsvector('simple'::regconfig, ((title || ' '::text) || COALESCE(artist, ''::text)))",
            Timeout:     3000000000,
            LockTimeout: 3000000000,
            Hazards:     nil,
        },
    },
    CurrentSchemaHash: "22b8e78772d29e38",
}

It seems that pg-schema-diff is changing the ...generated always as ... to ...default...

Expected behavior

Use generated always as.

Context

pg-schema-diff version: Version=v0.9.0
Postgres version: 17
pg-schema-diff apply --dsn url --schema-dir db/

Activity

  1. added
    bug
    on Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions