【发布时间】:2015-05-15 09:50:21
【问题描述】:
我一直在尝试在时间戳字段中从第一个日期到最后一个日期生成一系列日期 (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
【问题讨论】:
-
一如既往地,请提供您的 Postgres 版本。你提到的“问题”到底是什么?
-
Postgres v9.3 - 抱歉!
标签: sql postgresql aggregate-functions generate-series