Reem
Reem

Reputation: 63

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.

Upvotes: 0

Views: 170

Answers (2)

Vao Tsun
Vao Tsun

Reputation: 51446

you can't alter table column type using where, because "where" is DML and "alter" is DDL. Use update whe

Upvotes: 2

pensnarik
pensnarik

Reputation: 1252

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.

Upvotes: 2

Related Questions