Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lheGA-00031I-3T for pgsql-bugs@arkaria.postgresql.org; Fri, 14 May 2021 20:18:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lheG9-0001LE-19 for pgsql-bugs@arkaria.postgresql.org; Fri, 14 May 2021 20:18:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lheG8-0001L6-Qk for pgsql-bugs@lists.postgresql.org; Fri, 14 May 2021 20:18:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lheG6-0006Jp-EO for pgsql-bugs@lists.postgresql.org; Fri, 14 May 2021 20:18:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14EKI2R42191864; Fri, 14 May 2021 16:18:02 -0400 From: Tom Lane To: Shay Rojansky cc: Vik Fearing , Amit Langote , pavel.boev@invitae.com, PostgreSQL mailing lists Subject: Re: BUG #16913: GENERATED AS IDENTITY column nullability is affected by order of column properties In-reply-to: References: <16913-3b5198410f67d8c6@postgresql.org> <7c02b352-a2e4-e71a-ae69-7e410daf5774@postgresfriends.org> <2441173.1615563048@sss.pgh.pa.us> <3fb6c576-182e-e664-f64a-a65a74da85de@postgresfriends.org> Comments: In-reply-to Shay Rojansky message dated "Fri, 14 May 2021 22:06:05 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2191862.1621023482.1@sss.pgh.pa.us> Date: Fri, 14 May 2021 16:18:02 -0400 Message-ID: <2191863.1621023482@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Shay Rojansky 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