Skip to content

Modifying a field to type :identity in a migration produces invalid SQL #4751

Description

@dabaer

Elixir version

1.20.1

Database and Version

Postgresql 18.1

Ecto Versions

3.14.1

Database Adapter and Versions (postgrex, myxql, etc)

Postgrex 0.22.3

Current behavior

Write a migration that modifies the field type:

def up do
  alter table(:my_table) do
    modify :field, :bigint
  end
end

def down do
  alter table(:my_table) do
    modify :field, :identity
  end
end

(In my case its a rollback, roll the migration back)

08:51:29.752 [info] == Running 20260712144432 App.Repo.Migrations.AddMyTableFieldIdentity.down/0

08:51:29.752 [info] alter table my_table
** (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near "GENERATED"

    query: ALTER TABLE "my_table" ALTER COLUMN "field" TYPE bigint GENERATED BY DEFAULT AS IDENTITY

Expected behavior

The migration should succeed. Based on a my search, the SQL syntax for adding an identity to an existing column should be "ADD GENERATED" as opposed to just "GENERATED", and it should not specify the type, as the field is already bigint.

Running the updated query manually succeeds:

ALTER TABLE "my_table" ALTER COLUMN "field" ADD GENERATED BY DEFAULT AS IDENTITY;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions