SELECT t.day FROM generate_series( (SELECT date_trunc('hour'::text, ( SELECT now()::timestamp without time zone - '71:00:00'::interval hour)) AS date_trunc), now()::timestamp without time zone, '01:00:00'::interval ) t(day)
SELECT t.day , a.stationid FROM generate_series( (SELECT date_trunc('hour'::text, ( SELECT now()::timestamp without time zone - '71:00:00'::interval hour)) AS date_trunc), now()::timestamp without time zone, '01:00:00'::interval ) t(day) CROSS JOIN autostation a
WITH X as ( SELECT t.day , a.stationid FROM generate_series( (SELECT date_trunc('hour'::text, ( SELECT now()::timestamp without time zone - '71:00:00'::interval hour)) AS date_trunc), now()::timestamp without time zone, '01:00:00'::interval ) t(day) CROSS JOIN autostation a ) SELECT X.* , log.* FROM X LEFT JOIN log ON X.day::text = log.obstime::text AND X.stationid::text = log.stationid::text;