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

From Brilliantov Kirill Vladimirovich
Subject Re: NEW in after insert trugger contained incorrect data
Date
Msg-id 5469F467.5090209@byterg.ru
Whole thread Raw
In response to NEW in after insert trugger contained incorrect data  (Brilliantov Kirill Vladimirovich <brilliantov@byterg.ru>)
List 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


pgsql-general by date:

Previous
From: Gabriel Sánchez Martínez
Date:
Subject: Re: invalid OID warning after disk failure
Next
From: Gabriel Sánchez Martínez
Date:
Subject: Re: invalid OID warning after disk failure