SELECT *
FROM crosstab(
'SELECT
CONCAT(v.date, $$-$$, p.device_id) AS device,
v.date,
p.device_id,
v.param_id,
v.value
FROM
values AS v
JOIN params AS p ON p.id = v.param_id
ORDER BY
device',
'SELECT
id
FROM
params
ORDER BY
id') AS (
device VARCHAR,
date TIMESTAMP,
device_id INT,
par1 DOUBLE PRECISION,
par2 DOUBLE PRECISION,
par3 DOUBLE PRECISION
)