Re: DEFERRABLE NOT NULL constraint

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Andreas Joseph Krogh *EXTERN*" <andreak(at)officenet(dot)no>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: DEFERRABLE NOT NULL constraint
Date: 2013-02-05 08:59:54
Message-ID: A737B7A37273E048B164557ADEF4A58B057AFA16@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andreas Joseph Krogh wrote:
> It's currently (9.2) not possible to define DEFERRABLE NOT NULL constraints. Meaning the following is
> not valid:
>
> CREATE TABLE my_table(
> id varchar PRIMARY KEY,
> stuff_id BIGINT NOT NULL DEFERRABLE INITIALLY DEFERRED
> );
>
> While it's possible to define a trigger to enforce this, like this:
>
> CREATE CONSTRAINT TRIGGER my_table_t AFTER INSERT OR UPDATE ON onp_crm_relation DEFERRABLE INITIALLY
> DEFERRED
> FOR EACH ROW EXECUTE PROCEDURE my_table_check_stuff_id_nn_tf();
>
> And have the my_table_check_stuff_id_nn_tf() raise an exception if "stuff_id" is null.
>
> Having deferrable constraints on FKs and UKs is really nice and when working with ORMs it's almost
> impossible to not use this feature.
>
> Are there any plans to make NOT NULL constraints deferrable so one can avoid the trigger
> "boilerplate"?

Not that I know of.

There's an entry in the TODO list that recognizes that it would
be desirable to make NOT NULL a regular constraint (you can do
that today by using CHECK (col IS NOT NULL) instead).

But CHECK constraints are also not deferrable...

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Joseph Krogh 2013-02-05 09:22:18 Re: DEFERRABLE NOT NULL constraint
Previous Message nvardar 2013-02-05 07:09:40 BUG #7850: left outer join is not working or I didn't contruct the query properly