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 1i9fRh-0002qp-DQ for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 01:04:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i9fRd-0007HR-LW for pgsql-general@arkaria.postgresql.org; Mon, 16 Sep 2019 01:04:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9fRd-0007H2-Ar for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 01:04:45 +0000 Received: from mailbackend.panix.com ([166.84.1.89]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i9fRa-0002DO-Cg for pgsql-general@lists.postgresql.org; Mon, 16 Sep 2019 01:04:44 +0000 Received: from panix2.panix.com (panix2.panix.com [166.84.1.2]) by mailbackend.panix.com (Postfix) with ESMTP id 46Wp1N0Snsz1NZR; Sun, 15 Sep 2019 21:04:39 -0400 (EDT) Received: by panix2.panix.com (Postfix, from userid 17622) id 46Wp1M6Lg7z1ZVT; Sun, 15 Sep 2019 21:04:39 -0400 (EDT) Date: Sun, 15 Sep 2019 21:04:39 -0400 From: stan To: Adrian Klaver Cc: pgsql-general@lists.postgresql.org Subject: Re: FW: Re: FW: Re: Shouldn;t this trigger be called? Message-ID: <20190916010439.GA7478@panix.com> References: <20190915174649.GB2078@panix.com> <50d5b256-74b9-1949-a634-0df37cbfb783@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50d5b256-74b9-1949-a634-0df37cbfb783@aklaver.com> X-Editor: gVim User-Agent: Mutt/1.12.1 (2019-06-15) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Sep 15, 2019 at 12:27:14PM -0700, Adrian Klaver wrote: > On 9/15/19 10:46 AM, stan wrote: > > Forgot to cc the list again. Have to look at settings in mutt. > > > > > > > > > > > > Sorry forgot to cc the list > > > > > > > > > > On Sun, Sep 15, 2019 at 08:42:02AM -0700, Adrian Klaver wrote: > > > > > > On 9/15/19 8:33 AM, stan wrote: > > > > > > > I have defined this function: > > > > > > > > > > > > > > CREATE FUNCTION fix_customer_types_case() > > > > > > > > > > > > > > and this trigger: > > > > > > > > > > > > > > CREATE TRIGGER fix_customer_types_case_trig BEFORE INSERT OR UPDATE ON customer > > > > > > > FOR EACH ROW EXECUTE FUNCTION fix_customer_types_case(); > > > > > > > > > > > > > > and I put a RAISE NOTICE so I can tell if the function is called. Yet when I > > > > > > > do a : > > > > > > > > > > > > > > \copy to bring data into this table, I do not see the notice. > > > > > > > > > > > > What is the actual command you are using? > > > > > > > > > > > > > > > \COPY customer(name, location, status , c_type , bill_attention , bill_addresse , bill_address_1 , bill_address_2 , bill_city , bill_state , bill_country , ship_attention , ship_addresse , ship_address_1 , ship_address_2, ship_city ,ship_state ) from '/home/stan/pm_db/live_data/ready/customer.csv' DELIMITER ',' CSV HEADER ; > > > > > > > > > > and here is the function > > > > > > > > > > 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; > > > > > RAISE NOTICE 'Left With With %', NEW.c_type; > > > > > return NEW; > > > > > END; > > > > > $$ > > > > > LANGUAGE PLPGSQL; > > > > > > > > > > if I do an insert this function is called. However it IS NOT called for the > > > > > above copy command. How can I fix that? > > > > > > > > I thought you said it was fixed now. > > > > > > > I discovered that the function was not getting defined, and fixed that. Then I > > > rashly posted to the list that it was fixed, as i was certain that was the > > > only issue. But after I reported that, I tried testing, with he results in > > > this email. > > > > > > Works for INSERT, but does not fire on this \copy command. > > > > > More interesting data. I used vi to correct the incorrect case in the CSV file > > being imported, and re-ran the \copy command. At this point in time, I did > > see the messages from notice. I deleted the rows, re-edited back to the > > incorrect case in the csv file, and the import ((\copy) failed. > > > > 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. -- "They that would give up essential liberty for temporary safety deserve neither liberty nor safety." -- Benjamin Franklin