Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Shay Rojansky <roji@roji.org>
Cc: Vik Fearing <vik@postgresfriends.org>,
Amit Langote <amitlangote09@gmail.com>, pavel.boev@invitae.com,
PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2021-05-14T21:18:40Z
Lists: 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
Commits
-
Doc: correct erroneous entry in this week's minor release notes.
- e5f982156952 10.18 landed
- 6a4c07156802 13.4 landed
- 0a536004b7d9 12.8 landed
- 037cc13f413d 11.13 landed
-
Forbid marking an identity column as nullable.
- f52c5d6749a6 14.0 landed
- e7f7950f6741 12.7 landed
- e5794cd59394 10.17 landed
- 8a2297776667 13.3 landed
- 6c34f186c4c6 11.12 landed