Re: DEFERRABLE NOT NULL constraint

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Bèrto ëd Sèra <berto(dot)d(dot)sera(at)gmail(dot)com>
Cc: Chris Angelico <rosuav(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: DEFERRABLE NOT NULL constraint
Date: 2013-02-05 14:25:51
Message-ID: CAF-3MvMGGTHT4w76etNNkQtSNj423si7qwn=sB1wTiT8BHZY2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5 February 2013 14:20, Bèrto ëd Sèra <berto(dot)d(dot)sera(at)gmail(dot)com> wrote:

> Hi Chris,
>
> > I don't see
> > any reason to create a record with a NULL and then replace that NULL
> > before committing. Sort out program logic first; then look to the
> > database.
>
> I beg to differ here. Say you have a set of business rules that
> rigidly defines how that field must be made AND the data on which it
> is based is not visible to the user who does the insert. At this point
> you need "something" to generate that value on the fly for the user
> (calling a procedure from a before insert trigger).

You need that "something" either way, whether you supply it before the
record is inserted or after. Stuff like that is best done as database
logic, by means of a trigger or rule.

I have to admit that I don't know off the top of my head whether a NOT NULL
constraint fires before ON INSERT triggers or after and I don't have access
to PG from here to check that.
If that's the problem, then you might need to put a RULE in place instead
of an ON BEFORE INSERT trigger. Is that what your complaint boils down to?

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2013-02-05 14:27:36 Re: tablespace directories
Previous Message Andreas Joseph Krogh 2013-02-05 14:24:36 Re: DEFERRABLE NOT NULL constraint