PostgreSQL查询时间戳数组

时间:2013-11-30 07:22:34

标签: sql database postgresql

我有一个包含varchar数组列的表,其中包含时间戳数据。如何使用日期范围查询此表?

这样的事情:

select * 
from events 
where any(occurrences::timestamp[]) between '2013-11-30' and '2013-12-01'

1 个答案:

答案 0 :(得分:1)

WITH tbl AS(
    SELECT *, unnest(occurrences::timestamp[]) itm
    FROM events 
)
SELECT DISTINCT * 
FROM tbl
WHERE 
  itm BETWEEN '2013-10-01 00:00:00 UTC'::timestamp AND '2013-11-01 00:00:00 UTC' ::timestamp