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 <<a href="mailto:laurenz(dot)albe(at)wien(dot)gv(dot)at" target="_blank">laurenz(dot)albe(at)wien(dot)gv(dot)at</a>>:</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>
> It's currently (9.2) not possible to define DEFERRABLE NOT NULL constraints. Meaning the following is<br>
> not valid:<br>
><br>
> CREATE TABLE my_table(<br>
> id varchar PRIMARY KEY,<br>
> stuff_id BIGINT NOT NULL DEFERRABLE INITIALLY DEFERRED<br>
> );<br>
><br>
> While it's possible to define a trigger to enforce this, like this:<br>
><br>
> CREATE CONSTRAINT TRIGGER my_table_t AFTER INSERT OR UPDATE ON onp_crm_relation DEFERRABLE INITIALLY<br>
> DEFERRED<br>
> FOR EACH ROW EXECUTE PROCEDURE my_table_check_stuff_id_nn_tf();<br>
><br>
> And have the my_table_check_stuff_id_nn_tf() raise an exception if "stuff_id" is null.<br>
><br>
> Having deferrable constraints on FKs and UKs is really nice and when working with ORMs it's almost<br>
> impossible to not use this feature.<br>
><br>
> Are there any plans to make NOT NULL constraints deferrable so one can avoid the trigger<br>
> "boilerplate"?<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 "I want to sponsor development of <feature-X> with $xxx" mechanism?</div>
<div> </div>
<div class="origo-email-signature">--<br>
Andreas Joseph Krogh <andreak(at)officenet(dot)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>
<div> </div>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 2.1 KB |
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 |