Reputation: 87
In my redshift table, I have a column that has timestamp stored as - '2019-09-03 00:00:00'. I want to extract just the date out of it.
Tried both to_date and trunc function
select col, min(date) from table group by col
Also tried
select col, trunc(min(date)) from table group by col
I am still getting proper timestamp and not just date part.
Upvotes: 0
Views: 486
Reputation: 5084
In redshift truncating timestamp will always give you timestamp back, but it's not a big deal - you can still store it efficiently, filter using it, group by it etc. If you really want to store just the date then cast your timestamp object to date.
select '2019-09-03 01:13:11' str, str::timestamp as ts, date_trunc('day', ts), str::date as d
str ts date_trunc d
2019-09-03 01:13:11 2019-09-03 01:13:11.000000 2019-09-03 00:00:00.000000 2019-09-03
Upvotes: 1