Re: NEW in after insert trugger contained incorrect data

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "brilliantov(at)byterg(dot)ru" <brilliantov(at)byterg(dot)ru>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: NEW in after insert trugger contained incorrect data
Date: 2014-11-14 11:24:10
Message-ID: A737B7A37273E048B164557ADEF4A58B17D9E5BD@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gary Cowell 2014-11-14 11:41:15 Inconsistent results from HEX values in predicates
Previous Message Brilliantov Kirill Vladimirovich 2014-11-14 10:54:40 Re: NEW in after insert trugger contained incorrect data