Skip to content

EXCLUDE constraint incorrectly dumped as regular INDEX #281

@McVeyMason

Description

@McVeyMason

When doing a schema dump on tables with EXCLUDE USING gist constraints, the constraint is incorrectly converted to a regular CREATE INDEX statement, losing the exclusion semantics.

Repro SQL code

CREATE SCHEMA test;

CREATE TABLE test.test_table (
    id int PRIMARY KEY,
    org_id uuid NOT NULL,
    start_time timestamptz NOT NULL,
    end_time timestamptz NOT NULL,
    CONSTRAINT excl_no_overlap EXCLUDE USING gist (
        org_id WITH =,
        tstzrange(start_time, end_time, '[)') WITH &&
    )
);

Dump schema

pgschema dump --schema test

Expected output

CREATE TABLE IF NOT EXISTS test_table (
    id integer NOT NULL,
    org_id uuid NOT NULL,
    start_time timestamptz NOT NULL,
    end_time timestamptz NOT NULL,
    CONSTRAINT test_table_pkey PRIMARY KEY (id),
    CONSTRAINT excl_no_overlap EXCLUDE USING gist (org_id WITH =, tstzrange(start_time, end_time, '[)'::text) WITH &&)
);

Actual output

CREATE TABLE IF NOT EXISTS test_table (
    id integer NOT NULL,
    org_id uuid NOT NULL,
    start_time timestamptz NOT NULL,
    end_time timestamptz NOT NULL,
    CONSTRAINT test_table_pkey PRIMARY KEY (id)
);

CREATE INDEX IF NOT EXISTS excl_no_overlap ON test_table USING gist (org_id, tstzrange(start_time, end_time, '[)'::text));

The EXCLUDE constraint is converted to a regular gist INDEX, which:

  1. Loses the WITH = and WITH && operators that define the exclusion behavior
  2. Moves the constraint outside the table definition

Environment

  • PostgreSQL 18.1
  • pgschema v1.6.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions