Skip to content

Sequelize sync alters ENUM column comment with invalid USING clause causing PostgreSQL syntax error #17894

Closed

Description

@httpsdevil

Summary: Sequelize generates invalid SQL with an unsupported USING clause when syncing ENUM columns with comments in PostgreSQL.

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

When syncing a model using sequelize.sync({ alter: true, force: false }), Sequelize generates invalid SQL if the model contains an ENUM column with a comment.

This causes a PostgreSQL syntax error:

COMMENT ON COLUMN ... USING ...

The USING clause is not valid in a COMMENT statement.

Reproducible Example

Minimal example model:

const Appointment = sequelize.define('Appointment', {
status: {
type: DataTypes.ENUM('pending', 'confirmed', 'cancelled', 'completed'),
allowNull: false,
defaultValue: 'pending',
comment: 'Appointment lifecycle status',
}
}, {
tableName: 'appointments'
});

Sync code:

sequelize.sync({ alter: true, force: false })
.then(() => console.log("Synced!"))
.catch(err => console.error("Sync error:", err));

The error that occurs:

SequelizeDatabaseError: syntax error at or near "USING"

What do you expect to happen?

Expected behavior:
Sequelize should generate valid SQL to add or alter the comment without the USING clause:

COMMENT ON COLUMN "appointments"."status" IS 'Appointment lifecycle status';

What is actually happening?

This issue appears only during sync({ alter: true, force: false }) because Sequelize tries to alter the column comment by including an invalid USING clause, which PostgreSQL does not support for COMMENT statements.

Sequelize generates the following invalid SQL when altering a column:

COMMENT ON COLUMN "appointments"."status" IS 'Appointment lifecycle status' USING ("status"::"public"."enum_appointments_status");

which causes this PostgreSQL error:

PostgreSQL error: syntax error at or near "USING"

Note: The USING clause is only valid in an ALTER COLUMN ... TYPE ... USING statement, not in a COMMENT ON statement.

Also, when using force: true (which drops and recreates tables), this error does not occur because Sequelize skips the ALTER COLUMN statement.

Screenshot of error :

Image

Image

Environment

  • Sequelize version: 6.37.5
  • Node.js version: v20.12.2
  • TypeScript version: Not applicable
  • Database: PostgreSQL (version unknown)
  • Connector library: pg 8.13.1
  • pgAdmin version: 8.13

Would you be willing to resolve this issue by submitting a Pull Request?

[x] Yes, I have the time and I know how to start.

☑ Yes, I have the time but I will need guidance.

[x] No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.

[x] No, I don't have the time and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Activity

  1. added
    pending-approval
    on Jun 12, 2025
  2. added theissue type on Jun 12, 2025
  3. axolo commented on Oct 10, 2025

    @axolo

    +1

    define model:

    {
      status: {
          type: ENUM('OK', 'DISABLED'),
          allowNull: false,
          defaultValue: 'OK',
          comment: 'status,OK, DISABLED',
        }
    }

    generate sql:

    ALTER TABLE "app" ALTER COLUMN "status" SET NOT NULL;
    ALTER TABLE "app" ALTER COLUMN "status" SET DEFAULT 'OK';
    DO 'BEGIN CREATE TYPE "public"."enum_app_status" AS ENUM(''OK'', ''DISABLED'');
     EXCEPTION WHEN duplicate_object THEN null;
     END';
     ALTER TABLE "app" ALTER COLUMN "status" TYPE "public"."enum_app_status"  ;
     COMMENT ON COLUMN "app"."status" IS 'status,OK, DISABLED' USING ("status"::"public"."enum_app_status");

    error:

    SQL ERROR [42601]: ERROR: syntax error at or near "USING"
    
  4. added 2 commits that reference this issue on Jul 14, 2026
    da87c13
    f391101
  5. added a commit that references this issue on Aug 3, 2026
    1dfb88b
  6. added 2 commits that reference this issue on Sep 11, 2026
    ca5bf89
    67da6cc
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

    pending-approval

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions