Puede convertir avg_aa en bigint o en doble precisión. Primero reste la identificación y el nombre del campo de nombre y luego calcule el promedio por identificación y fecha.
-- PostgreSQL(v11)
WITH cte_t AS (
SELECT LEFT(name, 1) id
, RIGHT(name, POSITION('.' IN REVERSE(name)) - 1) t_name
, value
, time_stamp
FROM test
)
SELECT id
, time_stamp :: DATE "date"
, AVG(CASE WHEN t_name = 'aa' THEN value END) :: BIGINT "avg(aa)"
, AVG(CASE WHEN t_name = 'bb' THEN value END) :: BIGINT "avg(bb)"
, AVG(CASE WHEN t_name = 'cc' THEN value END) :: BIGINT "avg(cc)"
FROM cte_t
GROUP BY id, time_stamp :: DATE
ORDER BY "date", id;
Consulte desde la URL https://dbfiddle.uk/?rdbms=postgres_11&fiddle=8113ce4fd19d2865dcc5207d0e9
Usar precisión doble en la columna promedio
-- PostgreSQL(v11)
WITH cte_t AS (
SELECT LEFT(name, 1) id
, RIGHT(name, POSITION('.' IN REVERSE(name)) - 1) t_name
, value
, time_stamp
FROM test
)
SELECT id
, time_stamp :: DATE "date"
, AVG(CASE WHEN t_name = 'aa' THEN value END) :: DOUBLE PRECISION "avg(aa)"
, AVG(CASE WHEN t_name = 'bb' THEN value END) :: DOUBLE PRECISION "avg(bb)"
, AVG(CASE WHEN t_name = 'cc' THEN value END) :: DOUBLE PRECISION "avg(cc)"
FROM cte_t
GROUP BY id, time_stamp :: DATE
ORDER BY "date", id;
Consulte desde la URL https://dbfiddle.uk/?rdbms=postgres_11&fiddle=c70fe828008b13f7eb3feefc080 8038