Skip to content

CHECK (x IS NULL OR x IN (...)) generates unbalanced parentheses #271

@das-monki

Description

@das-monki

Version: pgschema v1.6.1

Minimal reproduction

-- minimal.sql
CREATE TABLE test (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    status TEXT CHECK (status IS NULL OR status IN ('A', 'B', 'C'))
);

pgschema apply results in:

Plan: 1 to add.

Summary by type:
  tables: 1 to add

Tables:
  + test

DDL to be executed:
--------------------------------------------------

CREATE TABLE IF NOT EXISTS test (
    id uuid DEFAULT gen_random_uuid(),
    status text,
    CONSTRAINT test_pkey PRIMARY KEY (id),
    CONSTRAINT test_status_check CHECK (status IS NULL OR (status IN ('A'::text, 'B'::text, 'C'::text))
);

Applying changes...

Executing group 1/1...
  Executing 1 statements in implicit transaction
Error: failed to execute concatenated statements in group 1: ERROR: syntax error at or near ";" (SQLSTATE 42601)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions