Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase add-foreign-key-constraint deferrable: what does it mean?

Tags:

liquibase

Looking at the docs for liquibase and add-foreign-key-constraint there is a property called deferrable. But the docs don't really mention what that property does. Anyone know?

like image 892
Gregg Avatar asked Jul 10 '12 00:07

Gregg


1 Answers

DEFERRABLE
NOT DEFERRABLE
This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable may be postponed until the end of the transaction (using the SET CONSTRAINTS command). NOT DEFERRABLE is the default. Only foreign key constraints currently accept this clause. All other constraint types are not deferrable.

[Source] http://www.postgresql.org/docs/8.1/static/sql-createtable.html

In short, assume two tables have cyclic FK dependency. When we perform insert data for which reference data is not present in both tables and FK constraint is not deferred, the DB would throw error since there is a violation of FK constraint. If deferred, the validation would be performed at the time of committing a transaction.

like image 60
devang Avatar answered Oct 17 '22 00:10

devang