Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pf2bB-000460-Di for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Mar 2023 17:50:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pf2bA-0004WH-Cg for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Mar 2023 17:50:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pf2bA-0004W8-1t for pgsql-hackers@lists.postgresql.org; Wed, 22 Mar 2023 17:50:08 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pf2b7-00076y-Fi for pgsql-hackers@postgresql.org; Wed, 22 Mar 2023 17:50:07 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id B059E5C012D; Wed, 22 Mar 2023 13:50:03 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 22 Mar 2023 13:50:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1679507403; x=1679593803; bh=q2 VjcjzXKJlthUwV/MBj/RojG1albUifXRHxjVeK17I=; b=Pteyp3Ih+7TAvee5d6 0ftd6ai9zkwG5p24v9rS9DrG1X1hyfG3K+wjoULDPbTZC5frwneN9IzrmVAhNO5L qyvZsjREumPsgGpaC2FHP9xKi+aTNr1NRdJ6+g/8N7qVsYQhnlZxi3cGm4W2aOR0 nARQIeUE1nj70mmjdmHyGclIdiWFnxKcF84mZlAG8T6URxQBrZhMe2L5ULOwew84 7k5jipjF7L+B4az6PdlrmkSxR3/GQsgbY9wD9kf8rtmZM4OrANR5/Uf+ijl6k3KX nN1MH6ozm3howYWRARyOHBgEEkwUtYQcjKS84jDEhHPfuaPQSZqCbjI3C3Q3Gw5P xFQQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1679507403; x=1679593803; bh=q2VjcjzXKJlth UwV/MBj/RojG1albUifXRHxjVeK17I=; b=h2EK/x4ZlyR5WZfa3K6P9OGw2MGA2 mPb0y43II/mFns6wTrDPIxEJ846MPvdR+y5kY3rO5W/YUcojtTY1Cmvn9XZ8S5Sk lviL1Y6ktsR9/z0yXcl4Xy9bdhWB7DF5ud+RDmNtRTMMi0HvGhRIoThzyrViKIuv t4ItnJez1ScfcTXnZU74/e0iAUIPNVqbMaCNaV1rtAwtZXy3Mui4SGxuY4m8aR1X b2RaLnbeeL6AIy+PDTZHs2P2HVt6uTzXPjvPuWyssu5Ow+fIDnIMgzbBI+W2TKUN khzjgG448vQ1q4K2Nqe5HG/Usy2nNYljHiuk3VWJmf+m6CozzCWJU4tAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdegvddguddtjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgu rhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtf frrghtthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteev udeitedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 22 Mar 2023 13:50:01 -0400 (EDT) Date: Wed, 22 Mar 2023 10:50:00 -0700 From: Andres Freund To: torikoshia , tgl@sss.pgh.pa.us Cc: Daniel Gustafsson , Damir Belyalov , PostgreSQL Hackers , Danil Anisimow , Nikita Malakhov , a.lepikhov@postgrespro.ru Subject: Re: POC PATCH: copy from ... exceptions to: (was Re: VLDB Features) Message-ID: <20230322175000.qbdctk7bnmifh5an@awork3.anarazel.de> References: <483E1B59-4A80-450B-8685-7CC12762FD5A@anarazel.de> <2592557.1675663234@sss.pgh.pa.us> <39143e83571d59dfc04c75707fa0ea5a@oss.nttdata.com> <0DE0602F-CC12-40ED-B259-3AB91FB02C3B@yesql.se> <8ad8492ff9fae3481d87c7aab4e0aed0@oss.nttdata.com> <9a94e684d6528dff74de5959e97032f3@oss.nttdata.com> <8e5c596e47435e3b37b7a751ebcd9569@oss.nttdata.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8e5c596e47435e3b37b7a751ebcd9569@oss.nttdata.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Tom, see below - I wonder if should provide one more piece of infrastructure around the saved error stuff... Have you measured whether this has negative performance effects when *NOT* using the new option? As-is this does not work with FORMAT BINARY - and converting the binary input functions to support soft errors won't happen for 16. So I think you need to raise an error if BINARY and IGNORE_DATATYPE_ERRORS are specified. On 2023-03-22 22:34:20 +0900, torikoshia wrote: > @@ -985,9 +986,28 @@ CopyFrom(CopyFromState cstate) > > ExecClearTuple(myslot); > > + if (cstate->opts.ignore_datatype_errors) > + { > + escontext.details_wanted = true; > + cstate->escontext = escontext; > + } I think it might be worth pulling this out of the loop. That does mean you'd have to reset escontext.error_occurred after an error, but that doesn't seem too bad, you need to do other cleanup anyway. > @@ -956,10 +957,20 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext, > values[m] = ExecEvalExpr(defexprs[m], econtext, &nulls[m]); > } > else > - values[m] = InputFunctionCall(&in_functions[m], > - string, > - typioparams[m], > - att->atttypmod); > + /* If IGNORE_DATATYPE_ERRORS is enabled skip rows with datatype errors */ > + if (!InputFunctionCallSafe(&in_functions[m], > + string, > + typioparams[m], > + att->atttypmod, > + (Node *) &cstate->escontext, > + &values[m])) > + { > + cstate->ignored_errors++; > + > + ereport(WARNING, > + errmsg("%s", cstate->escontext.error_data->message)); That isn't right - you loose all the details of the message. As is you'd also leak the error context. I think the best bet for now is to do something like /* adjust elevel so we don't jump out */ cstate->escontext.error_data->elevel = WARNING; /* despite the name, this won't raise an error if elevel < ERROR */ ThrowErrorData(cstate->escontext.error_data); I wonder if we ought to provide a wrapper for this? It could e.g. know to mention the original elevel and such? I don't think NextCopyFrom() is the right place to emit this warning - it e.g. is also called from file_fdw.c, which might want to do something else with the error. From a layering POV it seems cleaner to do this in CopyFrom(). You already have a check for escontext.error_occurred there anyway. > @@ -3378,6 +3378,10 @@ copy_opt_item: > { > $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1); > } > + | IGNORE_DATATYPE_ERRORS > + { > + $$ = makeDefElem("ignore_datatype_errors", (Node *)makeBoolean(true), @1); > + } > | DELIMITER opt_as Sconst > { > $$ = makeDefElem("delimiter", (Node *) makeString($3), @1); I think we shouldn't add a new keyword for this, but only support this via /* new COPY option syntax */ copy_generic_opt_list: copy_generic_opt_elem Further increasing the size of the grammar with random keywords when we have more generic ways to represent them seems unnecessary. > +-- tests for IGNORE_DATATYPE_ERRORS option > +CREATE TABLE check_ign_err (n int, m int[], k int); > +COPY check_ign_err FROM STDIN WITH IGNORE_DATATYPE_ERRORS; > +1 {1} 1 > +a {2} 2 > +3 {3} 3333333333 > +4 {a, 4} 4 > + > +5 {5} 5 > +\. > +SELECT * FROM check_ign_err; > + I suggest adding a few more tests: - COPY with a datatype error that can't be handled as a soft error - test documenting that COPY FORMAT BINARY is incompatible with IGNORE_DATATYPE_ERRORS - a soft error showing the error context - although that will require some care to avoid the function name + line in the output Greetings, Andres Freund