pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: stan <stanb@panix.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: FW: Re: Shouldn;t this trigger be called?
Date: Sun, 15 Sep 2019 13:27:57 -0400
Message-ID: <20190915172757.GA20364@panix.com> (raw)
In-Reply-To: <35c56985-433c-5fd4-ea4b-d4b05aa512a9@aklaver.com>
References: <20190915155526.GA9056@panix.com>
	<35c56985-433c-5fd4-ea4b-d4b05aa512a9@aklaver.com>

On Sun, Sep 15, 2019 at 08:59:43AM -0700, Adrian Klaver wrote:
> On 9/15/19 8:55 AM, stan wrote:
> > 
> > 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.

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





view thread (24+ messages)  latest in thread

Message-ID: <20190915172757.GA20364@panix.com>
Permalink:  ../20190915172757.GA20364@panix.com/
Also on:    postgresql.org/message-id/20190915172757.GA20364@panix.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: stanb@panix.com, adrian.klaver@aklaver.com
  Subject: Re: FW: Re: Shouldn;t this trigger be called?
  In-Reply-To: <20190915172757.GA20364@panix.com>
  References: <20190915155526.GA9056@panix.com> <35c56985-433c-5fd4-ea4b-d4b05aa512a9@aklaver.com> <20190915172757.GA20364@panix.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox