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 1vknwD-002Lsw-0g for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 18:37:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vknwC-00FeHR-0p for pgsql-hackers@arkaria.postgresql.org; Tue, 27 Jan 2026 18:37:16 +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 1vknwB-00FeHI-2i for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 18:37:16 +0000 Received: from mail-dl1-x122c.google.com ([2607:f8b0:4864:20::122c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vknw9-002c1n-0l for pgsql-hackers@lists.postgresql.org; Tue, 27 Jan 2026 18:37:15 +0000 Received: by mail-dl1-x122c.google.com with SMTP id a92af1059eb24-11f1fb91996so12480157c88.1 for ; Tue, 27 Jan 2026 10:37:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769539033; x=1770143833; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zQeQwVH97yzbFrZZNL5dvNj8mmHqytybudLdF3cFH0Q=; b=TmSxAvDvikIVWG8peK+T44v3SWpxiu98SSeL3w38kfFIA1oWw9jF7OpjKgqq63DrwT ZtlszScgAQbv32ibkZ77kHoDd+5pJwgA2H/8jHjxrF/1wh2wg09ARnLDVaa0rCFHkkCs mqxYix3ZAJvXBMZ04tHZW1Vw948zyLJ1faP70Mp8n0TNQZjkSj/PqRndfNP6Y6qzu80c ygAziVOvDAGWXmHqhBmTs0P100+mymf4j6Mmdylfyc4R2KQ0gmx+87deVW4v3X1Y2gq3 9En4LPvHOvyxCkSS8Cmbdn0nhRJebgFd+MmGm9YutNBuN5hmKss3Vbxz10SymuZ5FwuS q5zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769539033; x=1770143833; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zQeQwVH97yzbFrZZNL5dvNj8mmHqytybudLdF3cFH0Q=; b=ftZ2ux2ipVEvIPmAYeN7gEX8ldwB0OvXXxBbFmsOBzxx/Ukpec7Od70yT4tgbv9fR8 zGo+H2RvKmdcgkGA1jIicczudebS5xi19XTdO7ishXnT36/H8xNnJde2jV0MUjbwlBJB riYSKrISat8+xVSWe75uHT/GXPcweBhDhLRS1I//ve6ETnAuSvb0XZC16nRdz7g54J3T 6h/0kAmyV0AmvZ5WjF1mMpTRtKW3BtELuFyfp5zSFtJqYRxzZ20x4izr+cq6uQ6yju/t ULquH3cuzxxe1hdHtm++jt5sTFMlC6g1Z9Ycu90s8bSNrnTblpa8w0hmo2RFEff3jFmX d9Kg== X-Forwarded-Encrypted: i=1; AJvYcCVzwE+DoaqQnkWDwRMbm9O9tneCOqGoPvkrB6JJWtZME9Fw7oVKjHa72FoqA6yaUIHU2GzTdfTeJR5FtImL@lists.postgresql.org X-Gm-Message-State: AOJu0YxqTziLNLypgSvoggzg3Z2kk2cObD6UplvvLh1rav5U42C1nyTz gzY9tyojgwBiWirI+NoS7T/OI9q2BJpfb9UqAvTn+FiST5zg3atXm3uO X-Gm-Gg: AZuq6aIMgB/f6nFSqx007vVOXS8sIMlnYQgsE5oDrPGRyrS6j/Rw9ohph3rAvarihdD aSOaKgsLurOroYH8a7mT95BbKvFQ4GnaVUHBctFoGzW7L3CGQ2Kplhu+89DMQaKOyc6T2HGLDNw ndnkWG9lciF/gjD2LcemkSqfACy1mGuQbubsrH5JanZVJpaNvMXEPHVBk1CGR+VhztipuZVLAgL ItL2hLQrPRINZIRzD+QVjWPKi5q4LYGDsv+rwKBMeIIBrXvUAE0j0pbYWFo5aZIML34mDL/vLLU MSFFM1tYTL+Ly+fhIupMGMzRbj32AogwDxdhCjqpVGuoHSzqAJukpreHQG9il1Zga02tBbQeOPh O4ZnNwOoxxQ00cBP9LYF6oH4Ox8Xg974ykVO/12UhIgTAyaYvjsyJzNE6Bq7xPppfGkFJe0AB+I OAmdcRmlPu/NsTH0bXsafpKiuyp5fis/xxyWYmGMa/B8en+A+uNc/RQnL3f5M8OKAodL490THop IxBj9g= X-Received: by 2002:a05:7022:6609:b0:11b:d4a8:d24d with SMTP id a92af1059eb24-124a009ba2amr1407719c88.12.1769539032679; Tue, 27 Jan 2026 10:37:12 -0800 (PST) Received: from ?IPV6:2804:14d:328a:a59c:8d86:2c76:bcc:3838? ([2804:14d:328a:a59c:8d86:2c76:bcc:3838]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a7c979a0sm502203c88.17.2026.01.27.10.37.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Jan 2026 10:37:12 -0800 (PST) Message-ID: <4c540fe3-495c-4bbf-8dcf-2c1e2b88bc3d@gmail.com> Date: Tue, 27 Jan 2026 15:37:07 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row To: jian he 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> Content-Language: en-US From: Matheus Alcantara 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 On 22/01/26 11:45, jian he wrote: >> 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? >> > FORCE_NOT_NULL is related to how we handle NULL string in column value. > > We first process cstate->opts.force_notnull_flags, cstate->opts.force_null_flags > then InputFunctionCallSafe. > see copyfromparse.c, CopyFromTextLikeOneRow ``if (is_csv)``loop. > > I think these two are unrelated things, FORCE_NOT_NULL should be fine with > ON_ERROR SET_NULL. > you can see related tests in > https://git.postgresql.org/cgit/postgresql.git/tree/src/test/regress/sql/copy2.sql#n330 > > Am I missing something? Yeah, after some more thinking it seems ok to use both options together. I just found a bit strange when using integer columns. Consider this example: cat data.csv 1,11 2,22 3, 4,44 postgres=# create table t(a int not null, b int); CREATE TABLE postgres=# copy t from '/Users/matheus/dev/pgdev/copy-on-error-set-null/data.csv' with (FORCE_NOT_NULL(b), format csv, delimiter ',', ON_ERROR set_null); NOTICE: 1 row was replaced with null due to data type incompatibility COPY 4 postgres=# select * from t where b is null; a | b ---+--- 3 | (1 row) We are requiring a not null value on column b but we are still generating rows with null values on b. The reasoning on this is that the row 3 would generate a "invalid input syntax for type integer" error and the ON_ERROR set_null fix this by inserting a NULL value. It make sense I think but I'm wondering if it could cause any confusion? >> 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 >> stop is specified to the ON_ERROR >> >> 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? >> > > IMHO, we don't need to mention ON_ERROR set_null, since we do not support it. > change to the following should be ok, i think. > > > Number of tuples skipped because they contain malformed data. > This counter only advances when > ignore is specified to the ON_ERROR > option. > It looks good, I was thinking in something like this. >> >> I may have missing something, but we are still considering implementing >> the REJECT_LIMIT + ON_ERROR set_null? > Possibly as a separate patch later. Ok, good, thanks. -- Matheus Alcantara EDB: https://www.enterprisedb.com