Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePKMf-0003Et-1l for pgsql-bugs@arkaria.postgresql.org; Thu, 14 Dec 2017 03:39:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ePKMe-0000Cj-CS for pgsql-bugs@arkaria.postgresql.org; Thu, 14 Dec 2017 03:39:16 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ePKMe-0000CY-6y for pgsql-bugs@lists.postgresql.org; Thu, 14 Dec 2017 03:39:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ePKMW-0000FY-PS for pgsql-bugs@postgresql.org; Thu, 14 Dec 2017 03:39:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vBE3d0DO031741; Wed, 13 Dec 2017 22:39:00 -0500 From: Tom Lane To: Michael Paquier cc: Peter Eisentraut , steven.winfield@cantabcapital.com, PostgreSQL mailing lists Subject: Re: BUG #14952: COPY fails to fill in IDENTITY column default value In-reply-to: References: <20171207112930.21696.79944@wrigleys.postgresql.org> <12618e2c-0eb0-3e15-c45d-96891c52eb5f@2ndquadrant.com> Comments: In-reply-to Michael Paquier message dated "Fri, 08 Dec 2017 10:37:15 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31739.1513222740.1@sss.pgh.pa.us> Date: Wed, 13 Dec 2017 22:39:00 -0500 Message-ID: <31740.1513222740@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > On Fri, Dec 8, 2017 at 2:13 AM, Peter Eisentraut > wrote: >> That indeed appears to be a bug. > That's a bug. When doing a COPY with or without a list of columns, and > that a column is not listed and has a default expression, then this > expression is used. This is a role filled in by build_column_default() > but identity columns need to create a NextValueExpr expression > instead. As this expression is missing, the backend complains about a > NULL input for this column, which is logic without an expression. > Attached is a patch with a regression test. Now that I look more closely at this patch, isn't it fixing things in the wrong place? Why is it that COPY needs to know about this, rather than build_column_default()? Aren't we going to have to fix every other caller of build_column_default()? For that matter, should build_column_default() know about it explicitly either? Why aren't we implementing IDENTITY by storing an appropriate default expression in the catalogs? regards, tom lane