Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rb4dr-00D1YF-VW for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Feb 2024 20:17:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rb4dq-0044Te-4S for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Feb 2024 20:17:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rb4dp-0044TQ-OP for pgsql-hackers@lists.postgresql.org; Fri, 16 Feb 2024 20:17:01 +0000 Received: from udcm-wwu1.uni-muenster.de ([128.176.118.7]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rb4dl-007Ydv-Ud for pgsql-hackers@lists.postgresql.org; Fri, 16 Feb 2024 20:17:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uni-muenster.de; i=@uni-muenster.de; q=dns/txt; s=uniout; t=1708114618; x=1739650618; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=nEltrtUzUWcVU+yQXfg4mFiDJ+TXUtsQ91qzjwUTmOA=; b=rx/fKKhFGnKvCA8O7ExlOswrbZyRGdQoIrFn9O6cSGPVHFeiQHOjQKub nlw9tQLwHuyl9syp9oPshFwj7ECz0ZTz8yR7dfcm6nAYdT0tXObDFBbNz v221hv7R/rJtTZXk5Ry3Gd3kIx18K4nVmratH/aNBUpV+yhPL/nLg549n hKIFiuy61x4oNYBCo9n+dPhguOB2RLaeztDbQhxBJQ5a+ehLok+SOBdSu O3cy7F5BwUvFzslNd62ysbN4JBZFJ+wdn4VnwE14Pg0B+IGpZzHU3MZ3g loFsxffg7MWQzM5UE1mCbG4ZkSo+FM8E6UiL2LdD6IbT+fLmyhps/X+wF A==; X-CSE-ConnectionGUID: ZP9B697KQjSY2kbCqO0exA== X-CSE-MsgGUID: SIKKgkAqRGKLtlQYZMsaEA== X-IronPort-AV: E=Sophos;i="6.06,165,1705359600"; d="scan'208";a="316353428" Received: from secmail.uni-muenster.de ([128.176.118.4]) by UDCM-RELAY1.UNI-MUENSTER.DE with ESMTP; 16 Feb 2024 21:16:57 +0100 Received: from [192.168.178.27] (dynamic-078-049-110-017.78.49.pool.telefonica.de [78.49.110.17]) by SECMAIL.UNI-MUENSTER.DE (Postfix) with ESMTPSA id 500CF20ADF19; Fri, 16 Feb 2024 21:16:55 +0100 (CET) Message-ID: <76da9fcc-93c5-4053-872e-12932a95356d@uni-muenster.de> Date: Fri, 16 Feb 2024 21:16:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row Content-Language: en-US To: jian he , Yugo NAGATA Cc: torikoshia , "David G. Johnston" , PostgreSQL Hackers References: <20240129172858.ccb6c77c3be95a295e2b2b44@sraoss.co.jp> <04bf425ad1b15a4daefe96c478a5253b@oss.nttdata.com> <20240206191937.72eaf0ccc20cfea37944b422@sraoss.co.jp> From: Jim Jones In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi! On 12.02.24 01:00, jian he wrote: > attached v2. > syntax: `on_error set_to_null` > based on upthread discussion, now if you specified `on_error > set_to_null` and your column has `not > null` constraint, we convert the error field to null, so it may error > while bulk inserting for violating NOT NULL constraint. That's a very nice feature. Thanks for implementing it! v2 applies cleanly and works as described. \pset null '(NULL)' CREATE TEMPORARY TABLE t1 (a int, b int); COPY t1 (a,b) FROM STDIN; 1    a 2    1 3    2 4    b a    c \. SELECT * FROM t1; CONTEXT:  COPY t1, line 1, column b: "a"  a | b ---+--- (0 rows) CREATE TEMPORARY TABLE t2 (a int, b int); COPY t2 (a,b) FROM STDIN WITH (on_error set_to_null); 1    a 2    1 3    2 4    b a    c \. SELECT * FROM t2; psql:test-copy-on_error-2.sql:12: NOTICE:  some columns of 3 rows, value were converted to NULL due to data type incompatibility COPY 5    a    |   b     --------+--------       1 | (NULL)       2 |      1       3 |      2       4 | (NULL)  (NULL) | (NULL) (5 rows) I have one question though: In case all columns of a record have been set to null due to data type incompatibility, should we insert it at all? See t2 example above. I'm not sure if these records would be of any use in the table. What do you think? Since the parameter is already called "set_to_null", maybe it is not necessary to mention in the NOTICE message that the values have been set to null. Perhaps something like "XX records were only partially copied due to data type incompatibility" -- Jim