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.96) (envelope-from ) id 1vv9Rd-005sHT-2U for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Feb 2026 07:36:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vv9Rc-004xJb-2C for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Feb 2026 07:36:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vv9Rb-004xJT-1w for pgsql-hackers@lists.postgresql.org; Wed, 25 Feb 2026 07:36:28 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vv9RY-000000015Fo-1XkX for pgsql-hackers@lists.postgresql.org; Wed, 25 Feb 2026 07:36:26 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 71B23EC0572; Wed, 25 Feb 2026 02:36:24 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 25 Feb 2026 02:36:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm2; t=1772004984; x=1772091384; bh=gnKKiush6AuBnnaRFVw6LaIEEmAx4WLT GoATRLPxxW8=; b=ZnPL5UPDuKVLp9MLr62cCSbHk//EktEJ7LL4ps5OKunqs3Fn EA3zAbMU+EPPGWtqvY3cPYm6zcG34Qn+pLt8VI5lXY5RReW1VLeoUvrtL7tdi8vW OFd99ijo3Yg1/okXpsZwUHhrMbS1wuaXvHZNtDmIay5L0WUg9qCO7rXRKKT0BMLl mWOf8ku0cAhO4k55OqSS8jZyy2IMZA1jJ0GtqM9e1usyEBFQ4tSWt6OpDVyC6B31 lexIZK734VwSDhZUD3R+0KnBXp/7jIjtJmXFrrTbYiizK2i+WDKyQydPvizHaC+b d4c6ZZm040NxghrHVqJUO4IGDot4jiODf9sLsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1772004984; x= 1772091384; bh=gnKKiush6AuBnnaRFVw6LaIEEmAx4WLTGoATRLPxxW8=; b=J VajC7+G3DpqHUSOD1mExJLE2yKLfxF/US8K6Ojbllt+T/fSm81NJc9QqGwLylX0m PYyi/Lv8ls+J7zYtqo9CK4giHMt4jfteH0F96eF0xEpA4sMsErVoTh2V1A7vV7YF XaHBK3gm0FJXijl/mZezI+ea+jwgwNdUgLf0Ff8hISTqjrQIn/UZk4TEy0f3ddt3 gIcrX86gy72VbucgFvmWyBqs0s+inzu65xR0mZBZ49caZhsNHmGTVZtWnZTYJVW9 aX9QJOw91ec7Cb1kxHLWH/8E+Kctob+Ag7vEQddHI02aKdXrw9HI6b2nI83J8OEg 4SwKFDKo2cKO4D3d9wJaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvgedvhedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpefrvghtvghr ucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgheqne cuggftrfgrthhtvghrnhepgfejtdfhkeeftdeugfeileehteeljeeghfeuledthfeutedv ffdukeefjefhgeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgpdhnsggprhgtphhtthho peduuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhirghnrdhunhhivhgvrh hsrghlihhthiesghhmrghilhdrtghomhdprhgtphhtthhopehmrghthhgvuhhsshhsihhl vheljeesghhmrghilhdrtghomhdprhgtphhtthhopehtohhrihhkohhshhhirgesohhssh drnhhtthgurghtrgdrtghomhdprhgtphhtthhopehsrgifrggurgdrmhhshhhksehgmhgr ihhlrdgtohhmpdhrtghpthhtohepvhhighhnvghshhdvudesghhmrghilhdrtghomhdprh gtphhtthhopehjihhmrdhjohhnvghssehunhhiqdhmuhgvnhhsthgvrhdruggvpdhrtghp thhtoheprhgvshhhkhgvkhhirhhilhhlsehgmhgrihhlrdgtohhmpdhrtghpthhtohepmh grshgrohdrfhhujhhiihesohhsshdrnhhtthgurghtrgdrtghomhdprhgtphhtthhopegu rghvihgurdhgrdhjohhhnhhsthhonhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Feb 2026 02:36:21 -0500 (EST) Message-ID: <6f973222-f306-43af-9df5-38673fe3f7d6@eisentraut.org> Date: Wed, 25 Feb 2026 08:36:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row To: jian he , Matheus Alcantara Cc: torikoshia , Masahiko Sawada , vignesh C , Jim Jones , Kirill Reshke , Fujii Masao , "David G. Johnston" , Yugo NAGATA , PostgreSQL Hackers References: <901967e5-e5dc-42c6-b2bf-fb3a49d7e787@gmail.com> <4c540fe3-495c-4bbf-8dcf-2c1e2b88bc3d@gmail.com> Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I have a few more cosmetic changes to suggest: - doc/src/sgml/ref/copy.sgml + and set_null means replace field containing invalid should be "the field" and "the invalid" + input value with NULL and continue to the next field. change NULL to "a null value" + + For ignore option, a NOTICE message + containing the ignored row count is emitted at the end of the COPY FROM + if at least one row was discarded. + For set_null option, a NOTICE + message indicating the number of rows where invalid input values were + replaced with null is emitted at the end of the COPY FROM + if at least one row was replaced. + I think this could be written more compactly, like If on_error is set to ignore or set_null, a NOTICE message is emitted at the end of the COPY FROM command containing the count of rows that were ignored or changed, if at least one row was affected. - src/backend/commands/copy.c /* - * Allow "stop", or "ignore" values. + * Allow "stop", "ignore", "set_null" values. */ Just remove that comment. It is evident from the following code. - src/backend/commands/copyfrom.c + "%" PRIu64 " rows were replaced with null due to data type incompatibility" I think this is not quite correctly worded. It should be something like in NNN rows, columns were set to null due to ... because you are not setting the whole row to null. /* - * Currently we only support COPY_ON_ERROR_IGNORE. We'll add other - * options later + * Currently we only support COPY_ON_ERROR_IGNORE, + * COPY_ON_ERROR_SET_NULL. We'll add other options later */ Delete this comment. + if (cstate->opts.on_error == COPY_ON_ERROR_SET_NULL) + { + int attr_count = list_length(cstate->attnumlist); + + cstate->domain_with_constraint = palloc0_array(bool, attr_count); Maybe add a comment for this block to explain that you are collecting information about domains for later. - src/backend/commands/copyfromparse.c /* - * If ON_ERROR is specified with IGNORE, skip rows with soft errors + * If ON_ERROR is specified with IGNORE, skip rows with soft errors. + * If ON_ERROR is specified with SET_NULL, try to replace with null. */ Trim this comment. Maybe "If ON_ERROR is specified, handle the different options". We don't need to re-explain here what the options do. + /* + * If the column type is a constrained domain, an additional + * InputFunctionCallSafe may be needed to raise error for + * domain constraint violation. + */ Why "may be needed"? Is it sometimes not needed? Why, under what circumstances? The subsequent error message writes "domain ... does not allow null values", but AFAICT a domain input failure could also be due to a check constraint failure? How would that be handled? The flow here is a bit confusing. - src/test/regress/sql/copy2.sql I suggest adding a space after "--" in a comment, like "-- error" instead of "--error". Similarly, a space after CHECK, like "CHECK (...)".