I am trying to migrate a column in a table from timestamp (double precision) to a Date.
For example, right now seen_timestamp column contains values like this one:
1643302746243
Values now are all UTC. So that unix timestamp would be:
Thu, 10 Mar 54044 17:04:03 GMT
Which is part of the mistake I made. The timestamp is supposed to be this:
1643302746.243
Which would be this date:
01/27/2022, 04:59:06 PM
So, I could first update all values by dividing by 1000, and then migrating over to UTC Date type....
I tried this:
ALTER TABLE car
ALTER COLUMN seen_timestamp TYPE DATE USING seen_timestamp::DATE;
I get the following error:
cannot cast type double precision to date
Makes sense. I just don't know how to change/migrate the column to Date type.
How can I make this work?
double precisionis not a "timestamp" to begin with. Atimestampis a timestamp. But to answer your question we would need to know what values does the column contain?TIMESTAMPwith a different name. 2) Update the new column converting the number to a timestamp. 3) Drop the existing BAD column. 4) Rename the new column to have the name of the old column.