Skip to content

Commit adec7cf

Browse files
committed
test: add failing test for EXCLUDE constraint WHERE clause being dropped
The deparser drops the WHERE clause from EXCLUDE USING ... WHERE (...) constraints. The parser correctly preserves where_clause in the AST, but the CONSTR_EXCLUSION handler in the deparser never outputs it. This causes partial exclusion constraints to lose their predicate during parse -> deparse cycles, which silently changes the constraint semantics.
1 parent ab3eacd commit adec7cf

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

__fixtures__/generated/generated.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21327,6 +21327,7 @@
2132721327
"misc/issues-15.sql": "select \"A\" from \"table_name\"",
2132821328
"misc/issues-16.sql": "select \"AA\" from \"table_name\"",
2132921329
"misc/issues-17.sql": "SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t",
21330+
"misc/issues-18.sql": "CREATE TABLE test_exclude_where (\n id uuid PRIMARY KEY,\n database_id uuid NOT NULL,\n status text NOT NULL DEFAULT 'pending',\n EXCLUDE USING btree (database_id WITH =)\n WHERE (status = 'pending')\n)",
2133021331
"misc/inflection-1.sql": "CREATE SCHEMA inflection",
2133121332
"misc/inflection-2.sql": "GRANT USAGE ON SCHEMA inflection TO PUBLIC",
2133221333
"misc/inflection-3.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA inflection \n GRANT EXECUTE ON FUNCTIONS TO PUBLIC",

__fixtures__/kitchen-sink/misc/issues.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ select "A" from "table_name";
7474
select "AA" from "table_name";
7575

7676
-- https://github.com/constructive-io/pgsql-parser/issues/217
77-
SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t;
77+
SELECT CAST(t.date AT TIME ZONE $$America/New_York$$ AS text)::date FROM tbl t;
78+
79+
-- EXCLUDE constraint with WHERE clause (partial exclusion constraint)
80+
-- The deparser drops the WHERE clause from EXCLUDE USING ... WHERE (...)
81+
CREATE TABLE test_exclude_where (
82+
id uuid PRIMARY KEY,
83+
database_id uuid NOT NULL,
84+
status text NOT NULL DEFAULT 'pending',
85+
EXCLUDE USING btree (database_id WITH =)
86+
WHERE (status = 'pending')
87+
);

packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ it('misc-issues', async () => {
2020
"misc/issues-14.sql",
2121
"misc/issues-15.sql",
2222
"misc/issues-16.sql",
23-
"misc/issues-17.sql"
23+
"misc/issues-17.sql",
24+
"misc/issues-18.sql"
2425
]);
2526
});

0 commit comments

Comments
 (0)