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 1kS2J5-00022q-AL for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Oct 2020 18:12:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kS2J4-0005ru-0e for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Oct 2020 18:12:22 +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 1kS2J3-0005rn-Qt for pgsql-bugs@lists.postgresql.org; Mon, 12 Oct 2020 18:12:21 +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 1kS2J1-0004S8-51 for pgsql-bugs@lists.postgresql.org; Mon, 12 Oct 2020 18:12:21 +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 09CICFBF3198998; Mon, 12 Oct 2020 14:12:15 -0400 From: Tom Lane To: "David G. Johnston" cc: =?UTF-8?Q?Jean_Pruli=C3=A8re?= , PostgreSQL mailing lists Subject: Re: Identity column behavior discrepancies when inserting one or many rows In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Mon, 12 Oct 2020 09:10:43 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3198996.1602526335.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 12 Oct 2020 14:12:15 -0400 Message-ID: <3198997.1602526335@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Mon, Oct 12, 2020 at 4:04 AM Jean Prulière wrote: >> Here is a very simple script to reproduce what we encountered : >> >> CREATE TABLE test ( >> id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, >> sometext text NOT NULL >> ); >> >> -- that one works : INSERT 0 1 >> -- I think it should not and throw a 428C9 >> INSERT INTO test (id, sometext) >> >> VALUES (DEFAULT, 'test'); >> >> -- this one does not : SQL state : 428C9 >> INSERT INTO test (id, sometext) >> >> VALUES (DEFAULT, 'test2'), >> (DEFAULT, 'test3'); > I agree the inconsistency seems to be undocumented but I wonder why the > second case doesn't work, not why the first one does. INSERT says: "For a > generated column, specifying this is permitted but merely specifies the > normal behavior of computing the column from its generation expression." > That says the first case works, default means the same as omitting the > column altogether. Yeah. Ideally both examples should work. The fact that the second one does not is an implementation deficiency: the code that recognizes no-op DEFAULTs for this purpose doesn't descend into multi-row VALUES lists. Somebody submitted a patch to improve that awhile ago, but I didn't like the first version and there hasn't been an update yet: https://commitfest.postgresql.org/30/2681/ Perhaps you could get your students interested in rewriting that patch? regards, tom lane