Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert time without time zone to timestamp without time zone?

Tags:

sql

postgresql

I need to convert couple of columns in one table in PSQL and I really dont want to drop the table to fix this (thats my last resort). Is there a way to do this, because when I write:

    ALTER TABLE table ALTER TABLE column type TIMESTAMP without time zone using column::TIMESTAMP without time zone; 

it doesnt work, says:

    ERROR:cannot cast type time without time zone to timestamp without time zone.

P.S. If its possible, I would like to avoid dropping columns because I already use indexes of those columns.

like image 301
Marko Petričević Avatar asked Mar 07 '17 13:03

Marko Petričević


1 Answers

If you want the date part to be today:

alter table the_table
alter column the_column type timestamp without time zone 
using current_date + the_column
like image 192
Clodoaldo Neto Avatar answered Nov 12 '22 06:11

Clodoaldo Neto