yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.9k stars 1.06k forks source link

[YSQL] Support DEFERRABLE constraints #4700

Open m-iancu opened 4 years ago

m-iancu commented 4 years ago

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

Analytics

bllewell commented 2 years ago

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: