[YSQL] Support DEFERRABLE constraints
m-iancu opened this issue · 1 comments
Jira Link: DB-2213
This is a master issue that keeps track of all deferrable constraints variants.
The check mark means that the statement is already supported.
Feature | Status | Tracking Issue | Comments |
---|---|---|---|
Foreign Key DEFERRABLE INITIALLY IMMEDIATE |
✅ | #3995 | |
Foreign Key DEFERRRABLE INITIALLY DEFERRED |
✅ | #3995 | |
Unique/Primary key DEFERRABLE INITIALLY IMMEDIATE |
⬜️ | #1709 | |
Unique/Primary key DEFERRABLE INITIALLY DEFERRED |
⬜️ | #1709 | |
Constraint triggers | ⬜️ | Constraint triggers not yet supported. | |
Exclusion constraint | ⬜️ | Exclusion constraints not yet supported. |
Dependent ecosystem projects:
Project | Status | Issues |
---|---|---|
Django | ⬜️ | #4054 |
The graphic above claims that deferred FK constraints work. Issue #13009 shows that they don't work in one of the examples that text books and bloggers frequently use to illustrate why deferred FK constraints are essential:
the optional (or mandatory) one-to-one relationship
Moreover, especially for the case that the PKs of the tables are automatically generated, proper practice recommends a stored procedure encapsulation of the three SQLs (insert returning, insert returning, and update using the returned values) that must be done in a single transaction.
As of this comment's timestamp, example code for this use case works faultlessly in vanilla PG. But it fails in YB:
- In the pure SQL implementation for the mandatory 1:1 case, you get a nonsensical error message that fails the txn.
- In the PG/pgSQL implementation for both the optional and the mandatory 1:1 case, you get a crash and the connection to the server is lost.