Re: NEW in after insert trugger contained incorrect data

From: Brilliantov Kirill Vladimirovich <brilliantov(at)byterg(dot)ru>
To: "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-17 13:13:11
Message-ID: 5469F467.5090209@byterg.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!
After modify trassa.update_cpu_load_list function on inserting one line
per time trigger work fine.

CREATE OR REPLACE FUNCTION trassa.update_cpu_load_list(device_id
integer, device_timestamp integer, device_cpu smallint[],
device_cpu_load smallint[])
RETURNS boolean AS
$BODY$
DECLARE
val_len SMALLINT DEFAULT array_length($3, 1);
-- cmd TEXT DEFAULT 'INSERT INTO trassa.cpu_load (device,
device_timestamp, cpu, value) VALUES';
result SMALLINT;
ts TIMESTAMP DEFAULT to_timestamp($2);
total_insert SMALLINT DEFAULT 0;
BEGIN
IF val_len = array_length($4, 1) THEN
FOR i IN 1..val_len LOOP
/*
cmd = cmd || '(' ||
$1::text ||
',''' || ts::text || ''',' ||
$3[i]::text || ',' ||
$4[i]::text || ')';
IF i != val_len THEN
cmd = cmd || ',';
END IF;
END LOOP;
EXECUTE cmd;
GET DIAGNOSTICS result = ROW_COUNT;
IF result = val_len THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
*/
EXECUTE 'INSERT INTO trassa.cpu_load (device, device_timestamp, cpu,
value) ' ||
'VALUES(' ||
$1::text ||
',''' || ts::text || ''',' ||
$3[i]::text || ',' ||
$4[i]::text || ')';
GET DIAGNOSTICS result = ROW_COUNT;
total_insert := total_insert + result;
END LOOP;
IF total_insert = val_len THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;

ELSE
RETURN FALSE;
END IF;
END;$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 100;

--
Best regards,
Brilliantov Kirill Vladimirovich

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gabriel Sánchez Martínez 2014-11-17 13:17:50 Re: invalid OID warning after disk failure
Previous Message Gabriel Sánchez Martínez 2014-11-17 13:10:13 Re: invalid OID warning after disk failure