You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deparser drops WHERE clause from EXCLUDE constraints #287
The deparser silently drops the WHERE clause from EXCLUDE constraints during parse → deparse cycles.
Input SQL
CREATETABLEtest_exclude_where (
id uuid PRIMARY KEY,
database_id uuid NOT NULL,
status textNOT NULL DEFAULT 'pending',
EXCLUDE USING btree (database_id WITH =)
WHERE (status ='pending')
);
Deparsed output
CREATETABLEtest_exclude_where (id uuid PRIMARY KEY, database_id uuid NOT NULL, status textNOT NULL DEFAULT 'pending', EXCLUDE USING btree (database_id WITH =))
The WHERE (status = 'pending') predicate is completely lost.
Root Cause
The CONSTR_EXCLUSION handler in packages/deparser/src/deparser.ts (lines ~3038-3070) handles access_method and exclusions but never checks or outputs node.where_clause.
The parser correctly preserves where_clause in the AST (verified — the constraint node has a full where_clause A_Expr), but the deparser never visits it.
Impact
This silently changes constraint semantics:
With WHERE: "only one pending row per database_id" (partial exclusion)
Without WHERE: "only one row per database_id ever" (total exclusion)
Discovered in constructive-db's database_transfer table — pgpm package uses the deparser to bundle SQL, and the bundled output was missing the WHERE clause.
Suggested Fix
In the CONSTR_EXCLUSION case, after the exclusions block and before the break:
Activity