DEFERRABLE NOT NULL constraint

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: DEFERRABLE NOT NULL constraint
Date: 2013-02-04 18:48:09
Message-ID: OrigoEmail.113.e0795ae98d01d64a.13ca67ff059@prod2.officenet.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<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(at)officenet(dot)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>

Attachment Content-Type Size
unknown_filename text/html 1.3 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message org.postgresql 2013-02-04 19:01:46 Options for passing values to triggers?
Previous Message Alexander Farber 2013-02-04 17:52:29 Re: Adding PRIMARY KEY: Table contains duplicated values