Re: trigger question

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: trigger question
Дата
Msg-id 20050818022604.GA69946@winnie.fuhr.org
обсуждение исходный текст
Ответ на trigger question  (Apu Islam <apuislam@gmail.com>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Kevin Murphy
Дата:
Сообщение: Re: speeding up a query on a large table
Следующее
От: "Premsun Choltanwanich"
Дата:
Сообщение: How to secure PostgreSQL Data for distribute?