Re: DEFERRABLE NOT NULL constraint

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Dean Rasheed *EXTERN*" <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Gavan Schneider *EXTERN* <pg-gts(at)snkmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: DEFERRABLE NOT NULL constraint
Date: 2013-02-07 10:51:35
Message-ID: A737B7A37273E048B164557ADEF4A58B057B0B81@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dean Rasheed wrote:
>> ISO/IEC 9075-2:2003 says:
>>
>> Chapter 10.8 (<constraint name definition> and <constraint characteristics>):
>>
>> <constraint characteristics> ::=
>> <constraint check time> [ [ NOT ] DEFERRABLE ]
>> | [ NOT ] DEFERRABLE [ <constraint check time> ]
>>
>> <constraint check time> ::=
>> INITIALLY DEFERRED
>> | INITIALLY IMMEDIATE
>>
>>
>> So yes, the standard caters for deferrable NOT NULL constraints.
>>
>> Moreover:
>>
>> Chapter 10.8, General Rules
>> 1) A <constraint name> identifies a constraint. Let the identified constraint be C.
>> 2) If NOT DEFERRABLE is specified, then C is not deferrable; otherwise it is deferrable.
>>
>> So deferrable should be the default.

> No. If you look at the Syntax Rules section just above that, it says:
>
> 1) If <constraint check time> is not specified, then INITIALLY
> IMMEDIATE is implicit.
> 2) Case:
> a) If INITIALLY DEFERRED is specified, then:
> i) NOT DEFERRABLE shall not be specified.
> ii) If DEFERRABLE is not specified, then DEFERRABLE is implicit.
> b) If INITIALLY IMMEDIATE is specified or implicit and neither
> DEFERRABLE nor NOT
> DEFERRABLE is specified, then NOT DEFERRABLE is implicit.
>
> So NOT DEFERRABLE is the default, if nothing else is specified.

The SQL standard is usually as confusing as is still
compatible with correctness, but after rereading the whole chapter
I think that here it is self-contradictory.

The syntax rules support what you say:
- If I specify nothing at all, INITIALLY IMMEDIATE is implicit.
- Since INITIALLY IMMEDIATE is implicit and neither DEFERRABLE
nor NOT DEFERRABLE are specified, NOT DEFERRABLE is implicit.

But how does that go together with General Rule 2?
It does not say "if NOT DEFERRABLE is specified or implicit",
it says "if NOT DEFERRABLE is specified".

Anyway, that's a sideline; at any rate the standard requires
deferrable NOT NULL constraints.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2013-02-07 10:59:00 Re: REINDEX deadlock - Postgresql -9.1
Previous Message Geoff Winkless 2013-02-07 10:46:53 Re: feature requests (possibly interested in working on this): functional foreign keys