Re: DEFERRABLE NOT NULL constraint

From: Andreas Joseph Krogh <andreak(at)officenet(dot)no>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: DEFERRABLE NOT NULL constraint
Date: 2013-02-05 09:22:18
Message-ID: OrigoEmail.15f.fdfc92f088952638.13ca9a7e242@prod2.officenet.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<div>På tirsdag 05. februar 2013 kl. 09:59:54, skrev Albe Laurenz &lt;<a href="mailto:laurenz(dot)albe(at)wien(dot)gv(dot)at" target="_blank">laurenz(dot)albe(at)wien(dot)gv(dot)at</a>&gt;:</div>

<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="display:inline; font-family: monospace; font-size: 12px;">Andreas Joseph Krogh wrote:<br>
&gt; It's currently (9.2) not possible to define DEFERRABLE NOT NULL constraints. Meaning the following is<br>
&gt; not valid:<br>
&gt;<br>
&gt; CREATE TABLE my_table(<br>
&gt; id varchar PRIMARY KEY,<br>
&gt; stuff_id BIGINT NOT NULL DEFERRABLE INITIALLY DEFERRED<br>
&gt; );<br>
&gt;<br>
&gt; While it's possible to define a trigger to enforce this, like this:<br>
&gt;<br>
&gt; CREATE CONSTRAINT TRIGGER my_table_t AFTER INSERT OR UPDATE ON onp_crm_relation DEFERRABLE INITIALLY<br>
&gt; DEFERRED<br>
&gt; FOR EACH ROW EXECUTE PROCEDURE my_table_check_stuff_id_nn_tf();<br>
&gt;<br>
&gt; And have the my_table_check_stuff_id_nn_tf() raise an exception if &quot;stuff_id&quot; is null.<br>
&gt;<br>
&gt; Having deferrable constraints on FKs and UKs is really nice and when working with ORMs it's almost<br>
&gt; impossible to not use this feature.<br>
&gt;<br>
&gt; Are there any plans to make NOT NULL constraints deferrable so one can avoid the trigger<br>
&gt; &quot;boilerplate&quot;?<br>
<br>
Not that I know of.<br>
<br>
There's an entry in the TODO list that recognizes that it would<br>
be desirable to make NOT NULL a regular constraint (you can do<br>
that today by using CHECK (col IS NOT NULL) instead).<br>
<br>
But CHECK constraints are also not deferrable...</div>
</blockquote>

<div> </div>

<div>+100 for having NOT NULL and CHECK-constraints deferrable:-)</div>

<div> </div>

<div>Is there any &quot;I want to sponsor development of &lt;feature-X&gt; with $xxx&quot; mechanism?</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>

<div> </div>

Attachment Content-Type Size
unknown_filename text/html 2.1 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Misa Simic 2013-02-05 09:37:37 Re: partial time stamp query
Previous Message Albe Laurenz 2013-02-05 08:59:54 Re: DEFERRABLE NOT NULL constraint