Re: NEW in after insert trugger contained incorrect data - Mailing list pgsql-general

From Albe Laurenz
Subject Re: NEW in after insert trugger contained incorrect data
Date
Msg-id A737B7A37273E048B164557ADEF4A58B17D9E5BD@ntex2010a.host.magwien.gv.at
Whole thread Raw
In response to Re: NEW in after insert trugger contained incorrect data  (Brilliantov Kirill Vladimirovich <brilliantov@byterg.ru>)
Responses Re: NEW in after insert trugger contained incorrect data  (Adrian Klaver <adrian.klaver@aklaver.com>)
List 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 by date:

Previous
From: Brilliantov Kirill Vladimirovich
Date:
Subject: Re: NEW in after insert trugger contained incorrect data
Next
From: Gary Cowell
Date:
Subject: Inconsistent results from HEX values in predicates