Re: trigger question

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Apu Islam <apuislam(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: trigger question
Date: 2005-08-18 02:26:04
Message-ID: 20050818022604.GA69946@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

[Please copy the mailing list on replies so others can contribute
to and learn from the discussion.]

On Wed, Aug 17, 2005 at 08:17:43PM -0500, Apu Islam wrote:
> However, I still get the error.. here is a sample very trim down version.
> I think the "hour" is the problem child. Anyone can give me some clues
> how to manage the variable substitution and string quoting on this
> trigger.
>
> CREATE FUNCTION cust_call_update() RETURNS TRIGGER AS '
> DECLARE
> hour INT ;
> BEGIN
> SELECT INTO hour date_part(''hour'', NEW.h323connecttime) ;
>
> INSERT INTO customer_stat (ip,connecttime,hour) VALUES
> (NEW.cisconasport, NEW.h323connecttime, date_part("hour",
> NEW.h323connecttime)) ;
>
> RETURN NULL ;
> END ;
> 'LANGUAGE 'plpgsql' ;

You're using a variable name (hour) that's the same as a column
name. When PL/pgSQL prepares the INSERT statement it thinks you
want the variable's value where you have the column name, so you
get an error. Rename the variable hour to something else.

Also, in this example, the first argument to date_part() should be
in single quotes (doubled or escaped since you're already inside a
quoted string), not double quotes.

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Premsun Choltanwanich 2005-08-18 02:56:49 How to secure PostgreSQL Data for distribute?
Previous Message Kevin Murphy 2005-08-18 02:00:40 Re: speeding up a query on a large table