Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iei4H-0006PW-8m for pgsql-general@arkaria.postgresql.org; Tue, 10 Dec 2019 16:08:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iei4G-0005Up-0Y for pgsql-general@arkaria.postgresql.org; Tue, 10 Dec 2019 16:08:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iei4F-0005Ui-Mx for pgsql-general@lists.postgresql.org; Tue, 10 Dec 2019 16:08:55 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iei4C-0008W7-R4 for pgsql-general@lists.postgresql.org; Tue, 10 Dec 2019 16:08:55 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 992FC223F7; Tue, 10 Dec 2019 11:08:51 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 10 Dec 2019 11:08:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=L rmdcHhT9CnNt3UgqbudxpS+2sDwEEqPUzviPpFZDXM=; b=Se1Ye5Wr0+qEnikmV 1a6xoW6AoKAg1TZ6R0/A2t9ezh6cvo+mdkfeuOjHwaheDdD1eEzLTks3sycA3y7a zs3KJLs9X+Aga7hXMldjiHIlicwbEMeEJsWIaCHSC28EHaY9CcY8xoWGriydCeBo 1odeEPoCoYhXSXQJJLrleXwnLYntGbIMf90c6HeUKTP1FNL5jlpCf8EsIoOwF2vV vccTWv8crZY4pL1RctzDDa1b8FatG4R8Qu5pAsJOS5CNCiO/lp7RZqqEomyWj/vH DOaO7RFtSxw0PLCEjQnDbSgbyrb309V6YxVIHEOy6TXCXdvqp3oHAWst+tHYvWyc pjhig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=LrmdcHhT9CnNt3UgqbudxpS+2sDwEEqPUzviPpFZD XM=; b=NTsG1J0vFlFzkGY5uhtb4elFtTXsXcdSxgHGReg2HW+e8ifKBtYw9/MaU v5sMR77sxDWP8UNY0v5yxq/7AkHaEp2htEfwv5AvuNlEBqZD+Upm2ONWp8gcI8C7 qnqyTTDNolsR2YlR09iBOZ5vC8zB9HxBdBOkurj6WV8wLE3X58Q02irp0F3NsoCw H9jGE+q5WDxL2IBxdslemwrc4ftHbUVx3zJp5Z7Ib7fFq7L+TDN4bJKn4ggLfumT O8jzVWE9IQusxS12wI+9i2cE975WPHcwPk3aByGbaHiTjER4Vdoal0XUJSfxqgpP Ci+GE0Bl9cwopY0SjcNxMnhSs6haw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudelfedgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghdpshhtrggtkhhovhgvrhhflhhofidrtghomhenucfkphepjedurddvuddv rddufeelrddujeenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.139.17]) by mail.messagingengine.com (Postfix) with ESMTPA id D943C8006A; Tue, 10 Dec 2019 11:08:50 -0500 (EST) Subject: Re: Identity columns, DEFAULT keyword and multi-row inserts To: Thomas Kellerer , pgsql-general@lists.postgresql.org References: <6615c093-b124-d680-e489-539ed98cf18b@gmx.net> From: Adrian Klaver Message-ID: Date: Tue, 10 Dec 2019 08:08:50 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <6615c093-b124-d680-e489-539ed98cf18b@gmx.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/10/19 12:15 AM, Thomas Kellerer wrote: > Patrick FICHE schrieb am 10.12.2019 um 08:56: >>> -----Original Message----- >>> From: Thomas Kellerer >>> >>> assume the following table: >>> >>> create table test >>> ( >>> id integer not null generated always as identity, >>> data integer not null >>> ); >>> >>> However, a multi-row insert like the following: >>> >>> insert into test (id, data) >>> values >>> (default,1), >>> (default,2); >>> >>> fails with: >>> >>> ERROR: cannot insert into column "id" >>> Detail: Column "id" is an identity column defined as GENERATED ALWAYS. >>> Hint: Use OVERRIDING SYSTEM VALUE to override. >>> >>> >>> My question is: >>> >>> * If DEFAULT is not allowed for identity columns, then why does the single-row insert work? >>> * If DEFAULT _is_ allowed, then why does the multi-row insert fail? >> >> >> I agree that it does not seem very consistent. >> >> But is there any specific reason why are you using DEFAULT ? >> >> If you want / have to specify DEFAULT, then you should probably >> create your identity as "generated by default". > I don't really need (or use) it, I just stumbled upon this: https://stackoverflow.com/questions/59261048 > > And I think if the single row insert is allowed the multi-row should be as well. > > Not sure if this is a bug - and if it is, which one is the bug: the failing statement or the working one? I would say the failing one: https://www.postgresql.org/docs/12/sql-insert.html "OVERRIDING SYSTEM VALUE Without this clause, it is an error to specify an explicit value (other than DEFAULT) for an identity column defined as GENERATED ALWAYS. This clause overrides that restriction. " > > > > > > > > > > -- Adrian Klaver adrian.klaver@aklaver.com