1

I have a table with a varchar array column that contains timestamp data. How can I query this table with a date range?

Something like this:

select * 
from events 
where any(occurrences::timestamp[]) between '2013-11-30' and '2013-12-01'
2
  • Please supply the table definition and some sample data including the expected output. Btw: You should never (really: never) store timestamps or dates as a string. And the problem you have now is a direct result of that wrong design. Commented Nov 30, 2013 at 8:05
  • sqlfiddle.com/#!15/51818/1 its a invalid result. The were condition need to run at same element. Commented Nov 30, 2013 at 8:44

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

That's probably a separate question, but is there an index on timestamp[] that would support such a query?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.