pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add COPY (on_error set_null) option
Date: Tue, 03 Mar 2026 06:37:25 +0000
Message-ID: <E1vxJNl-0027u6-0b@gemulon.postgresql.org> (raw)

Add COPY (on_error set_null) option

If ON_ERROR SET_NULL is specified during COPY FROM, any data type
conversion errors will result in the affected column being set to a
null value.  A column's not-null constraints are still enforced, and
attempting to set a null value in such columns will raise a constraint
violation error.  This applies to a column whose data type is a domain
with a NOT NULL constraint.

Author: Jian He <jian.universality@gmail.com>
Author: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: "David G. Johnston" <david.g.johnston@gmail.com>
Reviewed-by: Yugo NAGATA <nagata@sraoss.co.jp>
Reviewed-by: torikoshia <torikoshia@oss.nttdata.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://www.postgresql.org/message-id/flat/CAKFQuwawy1e6YR4S%3Dj%2By7pXqg_Dw1WBVrgvf%3DBP3d1_aSfe_%2...

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2a525cc97e19868940c533787165bc7e7de3a80a

Modified Files
--------------
doc/src/sgml/monitoring.sgml             |  4 +-
doc/src/sgml/ref/copy.sgml               | 30 +++++++----
src/backend/commands/copy.c              |  7 ++-
src/backend/commands/copyfrom.c          | 54 +++++++++++++++-----
src/backend/commands/copyfromparse.c     | 88 +++++++++++++++++++++++++++-----
src/bin/psql/tab-complete.in.c           |  2 +-
src/include/commands/copy.h              |  1 +
src/include/commands/copyfrom_internal.h |  7 +++
src/test/regress/expected/copy2.out      | 58 +++++++++++++++++++++
src/test/regress/sql/copy2.sql           | 43 ++++++++++++++++
10 files changed, 253 insertions(+), 41 deletions(-)



Message-ID: <E1vxJNl-0027u6-0b@gemulon.postgresql.org>
Permalink:  ../E1vxJNl-0027u6-0b@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vxJNl-0027u6-0b@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: peter@eisentraut.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Add COPY (on_error set_null) option
  In-Reply-To: <E1vxJNl-0027u6-0b@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox