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-14T20:18:02Z
Lists: pgsql-bugs
Shay Rojansky <roji@roji.org> writes:
> I can see the PG 13.3 change note about GENERATED ALWAYS AS IDENTITY no
> longer being compatible with an explicit NULL specification. However, it
> seems that GENERATED BY DEFAULT AS IDENTITY also is no longer compatible
> with null:
> CREATE TABLE foo
> (
> id INTEGER NULL GENERATED BY DEFAULT AS IDENTITY
> );
> Results in:
> ERROR: conflicting NULL/NOT NULL declarations for column "id" of table
> "foo"
> Is this intended?
GENERATED BY DEFAULT does create a NOT NULL constraint:
regression=# CREATE TABLE foo(id INTEGER GENERATED BY DEFAULT AS IDENTITY);
CREATE TABLE
regression=# \d foo
Table "public.foo"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+----------------------------------
id | integer | | not null | generated by default as identity
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.
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