Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties
Date
Msg-id 2194411.1621027120@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties  (Shay Rojansky <roji@roji.org>)
List pgsql-bugs
I wrote:
> GENERATED BY DEFAULT does create a NOT NULL constraint:
> ...
> so I think the patch is doing what it was intended to.  Whether GENERATED
> BY DEFAULT *should* be forcing NOT NULL is a separate question, but
> AFAIK it always has.

Ah, found it.  SQL:2016 11.4 <column definition> syntax rule 16 saith:

  If <identity column specification> ICS is specified, then:
  ...
  d) The <column constraint definition> NOT NULL NOT DEFERRABLE is implicit.

The <identity column specification> production includes both cases:

  <identity column specification> ::=
    GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY
        [ <left paren> <common sequence generator options> <right paren> ]

so the spec does clearly say that both alternatives force NOT NULL.

So, it was my error to write the release notes as though only
GENERATED ALWAYS is affected.  I'll go adjust that, though
it won't propagate to the website for another three months :-(

            regards, tom lane



pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties
Next
From: Peter Geoghegan
Date:
Subject: Re: BUG #16833: postgresql 13.1 process crash every hour