Skip to content

Incorrect closing parentheses for CREATE INDEX ... WHERE with an IN clause #264

@McVeyMason

Description

@McVeyMason

When doing a schema dump on partial indexes with multiple WHERE clauses with an enum IN, incorrect parentheses are generated.

Repro SQL code:

CREATE SCHEMA test;

CREATE TYPE test.enum_type AS ENUM ('one', 'two', 'three');

CREATE TABLE test.test_table ( id int PRIMARY KEY, col_one test.enum_type NOT NULL,  col_two int);

CREATE INDEX ix_test_partial_index_one_two ON test.test_table (col_one, col_two)
    WHERE (col_one IN ('one', 'two')) AND (col_two IS NOT NULL);

Dump schema:

pgschema dump --schema test

Expected index:

CREATE INDEX IF NOT EXISTS ix_test_partial_index_one_two ON test.test_table (col_one, col_two)
    WHERE (col_one IN ('one'::test.enum_type, 'two'::test.enum_type)) AND (col_two IS NOT NULL);

Actual output:

CREATE INDEX IF NOT EXISTS ix_test_partial_index_one_two ON test_table (col_one, col_two) 
   WHERE (col_one IN ('one'::test.enum_type, 'two'::test.enum_type])) AND (col_two IS NOT NULL));

Note the added ] and ).

After switching the order of the index, we get:

CREATE INDEX IF NOT EXISTS ix_test_partial_index_one_two ON test.test_table (col_one, col_two)
    WHERE (col_two IS NOT NULL) AND (col_one IN ('one'::test.enum_type, 'two'::test.enum_type) ;

Now, with a missing )

Enviroment:

  • PostgreSQL 18.1
  • pgschema v1.6.1

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