我一直在尝试在时间戳字段中从第一个日期到最后一个日期生成一系列日期(YYYY-MM-DD HH)。我有generate_series()
我需要的,但是在尝试从表格中获取开始日期和结束日期时遇到了问题。我有以下粗略的想法:
with date1 as
(
SELECT start_timestamp as first_date
FROM header_table
ORDER BY start_timestamp DESC
LIMIT 1
),
date2 as
(
SELECT start_timestamp as first_date
FROM header_table
ORDER BY start_timestamp ASC
LIMIT 1
)
select generate_series(date1.first_date, date2.first_date
, '1 hour'::interval)::timestamp as date_hour
from
( select * from date1
union
select * from date2) as foo
Postgres 9.3