Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9iNf-0002FG-Hu for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 04:12:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9iNc-0003WM-0P for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 04:12:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9iNb-0003Vn-Jm for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 04:12:47 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i9iNU-0006Ne-AG for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 04:12:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8G4CYbc010129; Mon, 16 Sep 2019 00:12:34 -0400 From: Tom Lane To: stan cc: Adrian Klaver , pgsql-general@lists.postgresql.org Subject: Re: FW: Re: FW: Re: Shouldn;t this trigger be called? In-reply-to: <20190916010439.GA7478@panix.com> References: <20190915174649.GB2078@panix.com> <50d5b256-74b9-1949-a634-0df37cbfb783@aklaver.com> <20190916010439.GA7478@panix.com> Comments: In-reply-to stan message dated "Sun, 15 Sep 2019 21:04:39 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10127.1568607154.1@sss.pgh.pa.us> Date: Mon, 16 Sep 2019 00:12:34 -0400 Message-ID: <10128.1568607154@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk stan writes: > On Sun, Sep 15, 2019 at 12:27:14PM -0700, Adrian Klaver wrote: >> On 9/15/19 10:46 AM, stan wrote: >>> So, my test tell me that the validity check is done BEFORE an attempt to >>> insert (thus firing the trigger) occurs. >> What validity check? > The check to see if it is the type enum. Indeed, a trigger cannot fix an input-validity error, because that will happen while trying to form the row value that would be passed to the trigger. So I guess that when you say "the trigger doesn't fire" you really mean "this other error is raised first". However, I still don't understand your claim that it works the way you wanted in an INSERT statement. The enum input function is going to complain in either context. Generally you need to fix issues like this before trying to insert the data into your table. You might try preprocessing the data file before feeding it to COPY. Another way is to copy into a temporary table that has very lax column data types (all "text", perhaps) and then transform the data using INSERT ... SELECT from the temp table to the final storage table. regards, tom lane