Re: DEFERRABLE NOT NULL constraint - Mailing list pgsql-general

From Albe Laurenz
Subject Re: DEFERRABLE NOT NULL constraint
Date
Msg-id A737B7A37273E048B164557ADEF4A58B057B0B81@ntex2010a.host.magwien.gv.at
Whole thread Raw
In response to Re: DEFERRABLE NOT NULL constraint  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-general
Dean Rasheed wrote:
>> ISO/IEC 9075-2:2003 says:
>>
>> Chapter 10.8 (<constraint name definition> and <constraint characteristi=
cs>):
>>
>> <constraint characteristics> ::=3D
>>     <constraint check time> [ [ NOT ] DEFERRABLE ]
>>   | [ NOT ] DEFERRABLE [ <constraint check time> ]
>>
>> <constraint check time> ::=3D
>>     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 const=
raint be C.
>> 2) If NOT DEFERRABLE is specified, then C is not deferrable; otherwise i=
t is deferrable.
>>
>> So deferrable should be the default.

> No. If you look at the Syntax Rules section just above that, it says:
>=20
> 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.
>=20
> 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

pgsql-general by date:

Previous
From: Geoff Winkless
Date:
Subject: Re: feature requests (possibly interested in working on this): functional foreign keys
Next
From: Scott Marlowe
Date:
Subject: Re: REINDEX deadlock - Postgresql -9.1