Sie könnten dies am einfachsten in Postgres so machen (mit Array-Spalten)
CREATE TEMP TABLE output AS SELECT
id, cat, ARRAY_AGG(realtime) as time, ARRAY_AGG(value) as values
FROM input GROUP BY id, cat;
Wählen Sie dann aus der Ausgabetabelle aus, was Sie wollen.