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 1i9wwV-0005VD-Ci for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 19:45:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9wwU-0007jg-5f for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 19:45:46 +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 1i9wwS-0007jM-MZ for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 19:45:45 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1i9wwP-0005ch-ML for pgsql-general@postgresql.org; Mon, 16 Sep 2019 19:45:43 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 4C6F021B2C; Mon, 16 Sep 2019 15:45:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 16 Sep 2019 15:45:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=9 UvD6qUOkX7QXYmuhp1lwtYklSef1erxuTlOWB4IFsk=; b=gGN6HJPi7EzgWJxxH vKYBIR8xAWlAjc15PbPkvaYDPqXgLSpAVJUay5+aho4TJvDVVJI/e1OEZ5UsCv40 7TsyOzGvftKKJMBGY0K3JIv9B51BqaUrJlJlLLYdAFqSYTYg25H/03tz54AZyyBo nOzgpta2Ej5XVm8m90t64z84VlA9N6sIcBlLv0t99XxsYsiaytPyGbf+kr9iyC6y pbwZ8z7wNJ2jTfX/OGk5amqA2uJDTWuwgzyfcIJoecSmxVrACI6lXI6rBKKPcGqK 6lrfKL80ZRrhGuXc/uApiScsE+n8lkYB4qQ4JsOzYxg3zEI/2JC1raCKys51mFb0 Vl04g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=9UvD6qUOkX7QXYmuhp1lwtYklSef1erxuTlOWB4IF sk=; b=DPANJay6J7GVvnxitUw2RR9RvH3t96+3fXoHysc5UdPo4kLhnN8KkGcmW xqUsGZbboGZRTSf8GZOYZI6bnyX8qw8txekJwB8kmmNQhRlOoTHzueXZHtiXV0/C 4vCsCSCDvbWLr3kBxdnIyidNVTnAIW/tliBXwq6ft2gx5338tkQGt4iZ17u6NaNt ErFKMVPhq/hQFYYh/l4It2tonbn5nivEefQn06v6QJVk7WgxDXkO59TAtPBdenTE xgf3Xd3wdiUFWqqxsZKx/vgRFsYLSF+CVbhXRTZzIi/zeuu3oZglS5oImhJ3pFhT sjvkDVi6M6rI9e1APayuT4iPJU0AQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudefgddugedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppedujeegrddvuddruddvledrud ejheenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedu X-ME-Proxy: Received: from [192.168.1.3] (174-21-129-175.tukw.qwest.net [174.21.129.175]) by mail.messagingengine.com (Postfix) with ESMTPA id 807F880062; Mon, 16 Sep 2019 15:45:39 -0400 (EDT) Subject: Re: FW: Re: FW: Re: Shouldn;t this trigger be called? To: stan , Tom Lane Cc: pgsql-general@postgresql.org References: <20190915174649.GB2078@panix.com> <50d5b256-74b9-1949-a634-0df37cbfb783@aklaver.com> <20190916010439.GA7478@panix.com> <10128.1568607154@sss.pgh.pa.us> <20190916185208.GA28966@panix.com> From: Adrian Klaver Message-ID: Date: Mon, 16 Sep 2019 12:45:38 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190916185208.GA28966@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/16/19 11:52 AM, stan wrote: > On Mon, Sep 16, 2019 at 12:12:34AM -0400, Tom Lane wrote: >> 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 > Thanks for educating me. I thought I had tested and seen that this worked on > an INSERT, but once you told me it does not, I re tested to convince myself > that my test was invalid. let me show you what I was trying to do: > So was it invalid? > > > CREATE FUNCTION fix_customer_types_case() > RETURNS trigger AS $$ > BEGIN > if NEW.c_type IS NOT NULL > THEN > NEW.c_type := upper(cast( NEW.c_type AS TEXT)); > END IF ; > if NEW.status IS NOT NULL > THEN > /* > RAISE NOTICE 'Called With %', NEW.status; > */ > NEW.status := upper(cast( NEW.status AS TEXT)); > END IF ; > /* > RAISE NOTICE 'Left With With NEW.status %', NEW.status; > RAISE NOTICE 'Left With With NEW.c_type %', NEW.c_type; > */ > return NEW; > END; > $$ > LANGUAGE PLPGSQL; > > CREATE TRIGGER fix_customer_types_case_trig BEFORE INSERT OR UPDATE ON customer > FOR EACH ROW EXECUTE FUNCTION fix_customer_types_case(); > > all of this is to deal with columns defined as this user defined type. > > > CREATE TYPE activity_status AS ENUM ('ACTIVE' , > 'INACTIVE'); > > > Can you think of a better way to make the system "human data entry friendly"? > -- Adrian Klaver adrian.klaver@aklaver.com