pgschema icon indicating copy to clipboard operation
pgschema copied to clipboard

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

Open McVeyMason opened this issue 10 months ago • 0 comments

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

McVeyMason avatar Jan 28 '26 16:01 McVeyMason