Search code examples
sqlpostgresqlalter

alter column (using + where)


I work with postgresql 9.3, I use this query to convert timestamp column to UTC.

ALTER TABLE table 
ALTER timestamp TYPE timestamp 
USING timestamp AT TIME ZONE 'UTC' ;

I need to add WHERE cluose to the query :

ALTER TABLE table 
ALTER timestamp TYPE timestamp where timestamp < '2015-01-06 00:00:00'
USING timestamp AT TIME ZONE 'UTC' ;

but, this is didn't work . there no clear resource on how to do it.


Solution

  • You could apply ALTER TYPE construction only to whole column, not to some rows. If you want to convert timestamp value you should use UPDATE instead.