Search Postgresql Archives

Re: NEW in after insert trugger contained incorrect data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux