Alagusundaram R
Alagusundaram R

Reputation: 7

current_date in redshift exclude today's date when i am using with between command

I want to query data for last 30 days including today from redshift table. below is my query.

my date_column's type is 'timestamp without timezone'

select * 
from mytable  
WHERE  date_column BETWEEN current_date - INTERVAL '30 day' AND current_date 
order by date_column desc;

It gives the result for 30 days. But it doesn't include today's result.

I want to query for 30 days result including today's result also.

Upvotes: 0

Views: 1405

Answers (1)

user330315
user330315

Reputation:

If it's a timestamp don't use between as it also compares the time part. Use a range query:

where date_column >= current_date - interval '30 day'
  and date_column < current_date + interval '1 day'

Note that the upper bound is using < together with "tomorrow"

With Postgres this could be simplified to

where date_column >= current_date - 30
  and date_column < current_date + 1

but Redshift isn't Postgres and I don't know if that would work there.

Upvotes: 3

Related Questions