DEFERRABLE NOT NULL constraint
Andreas Joseph Krogh <andreak@officenet.no>
From: Andreas Joseph Krogh <andreak@officenet.no>
To: "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
Date: 2013-02-04T18:48:09Z
Lists: pgsql-general
Attachments
- (unnamed) (text/html)
<div>It's currently (9.2) not possible to define DEFERRABLE NOT NULL constraints. Meaning the following is not valid:</div> <div> </div> <div>CREATE TABLE my_table(</div> <div>id varchar PRIMARY KEY,</div> <div>stuff_id BIGINT NOT NULL <u>DEFERRABLE INITIALLY DEFERRED</u></div> <div>);</div> <div> </div> <div>While it's possible to define a trigger to enforce this, like this:</div> <div> </div> <div> <div>CREATE CONSTRAINT TRIGGER my_table_t AFTER INSERT OR UPDATE ON onp_crm_relation <u>DEFERRABLE INITIALLY DEFERRED</u></div> <div>FOR EACH ROW EXECUTE PROCEDURE my_table_check_stuff_id_nn_tf();</div> <div> </div> </div> <div>And have the <u>my_table_check_stuff_id_nn_tf()</u> raise an exception if "stuff_id" is null.</div> <div> </div> <div>Having deferrable constraints on FKs and UKs is really nice and when working with ORMs it's almost impossible to not use this feature.</div> <div> </div> <div>Are there any plans to make NOT NULL constraints deferrable so one can avoid the trigger "boilerplate"?</div> <div> </div> <div class="origo-email-signature">--<br> Andreas Joseph Krogh <andreak@officenet.no> mob: +47 909 56 963<br> Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no<br> Public key: http://home.officenet.no/~andreak/public_key.asc</div>