Re: NEW in after insert trugger contained incorrect data

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: NEW in after insert trugger contained incorrect data
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B17D9E5BD@ntex2010a.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: NEW in after insert trugger contained incorrect data  (Brilliantov Kirill Vladimirovich <brilliantov@byterg.ru>)
Ответы Re: NEW in after insert trugger contained incorrect data  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
Brilliantov Kirill Vladimirovich wrote:
>> You should post the table definition and the whole trigger; the error
>> message seems to refer to things you omitted in your quote.
> 
> Table with statistic:
> CREATE TABLE trassa.cpu_load_stat
> (
>    id serial NOT NULL,
>    device integer NOT NULL,
>    cpu smallint NOT NULL,
>    min_value smallint NOT NULL,
>    min_device_timestamp timestamp without time zone NOT NULL,
>    min_timestamp timestamp without time zone,
>    avg_value smallint NOT NULL,
>    avg_timestamp timestamp without time zone NOT NULL,
>    max_value smallint NOT NULL,
>    max_device_timestamp timestamp without time zone NOT NULL,
>    max_timestamp timestamp without time zone,
>    total_value bigint NOT NULL,
>    total_count integer NOT NULL,
[...]
> )

> Trigger:
> CREATE OR REPLACE FUNCTION trassa.update_cpu_load_stat()
>    RETURNS trigger AS
> $BODY$
[...]
>         UPDATE trassa.cpu_load_stat
>         SET min_value = cpu_min_value,
>             min_device_timestamp = cpu_min_device_timestamp,
>             min_timestamp = cpu_min_created_timestamp,
>             avg_value = CEIL((total_value + NEW.value) /
>                     (total_count + 1)),
>             avg_timestamp = NOW(),
>             max_value = cpu_max_value,
>             max_device_timestamp = cpu_max_device_timestamp,
>             max_timestamp = cpu_max_created_timestamp,
>             total_value = (total_value + NEW.value),
>             total_count = (total_count + 1)
>         WHERE id = line_id;

I'd say that the error message refers to this or the following query:

There is no field "value" in the table, and "NEW" represents a row in the table,
so the expression "NEW.value" does not make sense.

Yours,
Laurenz Albe

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

Предыдущее
От: Brilliantov Kirill Vladimirovich
Дата:
Сообщение: Re: NEW in after insert trugger contained incorrect data
Следующее
От: Gary Cowell
Дата:
Сообщение: Inconsistent results from HEX values in predicates