0

I am beginner with Postgres. I want to select the rows where Today is greater than an Array of Dates that I have stored.

This is what i wrote which does not work (error)

    SELECT
    bool_or(now()::date @> a_date) AS some_of_the_dates_lies_within_range
FROM
(SELECT unnest(dateofdeparture) AS a_date from alerts) as S0;

This is how my row is

SELECT unnest(dateofdeparture) AS a_date from alerts

a_date
2019-01-12
2019-01-13
2019-01-14
2019-01-15
2019-01-16
2019-01-17
2019-01-18

Any pointers help would be much appreciated.

1 Answer 1

1

You are probably looking for the ANY or ALL operator on the ARRAY type

Assuming that dateofdeparture is a DATE[] array , what you need is either

select * from alerts WHERE current_date > ANY (dateofdeparture);

OR

select * from alerts WHERE current_date > ALL (dateofdeparture);

Demo

Sign up to request clarification or add additional context in comments.

3 Comments

Are you sure it is not > ALL that is asked for?
That helped. So I am trying to filter all rows which are passed current date and this hopefully nailed it. select * from alerts WHERE NOT current_date < ANY (dateofdeparture);
@SouravChatterjee : So, ANY gave you the result you're expecting?

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.