(unnamed)

text/html

Filename: (unnamed)
Type: text/html
Part: 0
Message: DEFERRABLE NOT NULL constraint
<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 &quot;stuff_id&quot; 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 &quot;boilerplate&quot;?</div>

<div> </div>

<div class="origo-email-signature">--<br>
Andreas Joseph Krogh &lt;andreak@officenet.no&gt;      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>