CREATE OR REPLACE FUNCTION datastore_unpack(
data_times TIMESTAMP WITH TIME ZONE[],
data_values DOUBLE PRECISION[],
OUT data_time TIMESTAMP WITH TIME ZONE,
OUT data_value DOUBLE PRECISION
) RETURNS SETOF RECORD AS $$
SELECT $1[rowx] AS data_time, $2[rowx] AS data_value
FROM generate_series(1, array_upper($1, 1)) AS rowx;
$$ LANGUAGE SQL STABLE;
It takes two parallel arrays and unpacks them into a set of records.