Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row

From: "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com>
To: "jian he" <jian(dot)universality(at)gmail(dot)com>
Cc: "torikoshia" <torikoshia(at)oss(dot)nttdata(dot)com>, "Masahiko Sawada" <sawada(dot)mshk(at)gmail(dot)com>, "vignesh C" <vignesh21(at)gmail(dot)com>, "Jim Jones" <jim(dot)jones(at)uni-muenster(dot)de>, "Kirill Reshke" <reshkekirill(at)gmail(dot)com>, "Fujii Masao" <masao(dot)fujii(at)oss(dot)nttdata(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "Yugo NAGATA" <nagata(at)sraoss(dot)co(dot)jp>, "PostgreSQL Hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row
Date: 2026-01-21 18:47:51
Message-ID: DFUHPCSP86G0.11VU7FGWRRXM2@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed Jan 21, 2026 at 4:37 AM -03, jian he wrote:
> On Wed, Jan 21, 2026 at 3:55 AM Matheus Alcantara
> <matheusssilv97(at)gmail(dot)com> wrote:
>> Hi,
>>
>> The patch needs a new rebase, could you please send a new version?
>
> sure. please check the attached.

Thanks for the new version. I have some comments on this first round of
review:

+ errmsg_plural("invalid values in %" PRIu64 " row was replaced with null due to data type incompatibility",
+ "invalid values in %" PRIu64 " rows were replaced with null due to data type incompatibility",

I think that we could remove the "invalid values in" to make it
consistency with the COPY_ON_ERROR_IGNORE NOTICE

----------

+ cstate->domain_with_constraint = (bool *) palloc0(attr_count * sizeof(bool));

I think that we can use palloc_array?

----------

Should FORCE_NOT_NULL be allowed to be used with ON_ERROR set_null? It
seems to me that ON_ERROR set_null overwrite the FORCE_NOT_NULL
behaviour:

postgres=# create table t4(a int, b varchar(5));
CREATE TABLE

postgres=# copy t4 from 'data.csv' with (FORCE_NOT_NULL(b), format csv, delimiter ',', NULL 'NULL', ON_ERROR set_null);
NOTICE: invalid values in 2 rows were replaced with null due to data type incompatibility
COPY 5

postgres=# \pset null 'NULL'
Null display is "NULL".
postgres=# select * from t4;
a | b
---+------
1 | aaaa
2 | bbbb
2 | NULL
2 | NULL
5 | NULL
(5 rows)

Note that only the ccccc rows on .csv file was inserted with a NULL
value on b column. The 5,NULL row was inserted with a "NULL" string as a
value:

postgres=# select * from t4 where b is null;
a | b
---+------
2 | NULL
2 | NULL
(2 rows)

The contents of data.csv:
1,aaaa
2,bbbb
2,ccccc
2,ccccc
5,NULL

Perhaps we should block the usage of FORCE_NOT_NULL with ON_ERROR
SET_NULL?

----------

On monitoring.sgml we have the following for pg_stat_progress_copy
tuples_skipped:
Number of tuples skipped because they contain malformed data.
This counter only advances when a value other than
<literal>stop</literal> is specified to the <literal>ON_ERROR</literal>

IIUC we are not updating this view if we set a column to NULL due to an
error, perhaps this documentation should be updated to mention that it
will not be updated with ON_ERROR set_null?

----------

I may have missing something, but we are still considering implementing
the REJECT_LIMIT + ON_ERROR set_null?

--
Matheus Alcantara
EDB: https://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-01-21 18:57:58 Re: Having problems generating a code coverage report
Previous Message Nikolay Shaplov 2026-01-21 18:44:29 Re: [PATCH] ternary reloption type