2015-09-01 128 views
0

有一列planned_duration,以分钟为单位存储时间,其类型为integer。您需要将类型更改为间隔并转换现有数据。为此我写了这个SQL代码:更改列类型和数据转换

ALTER TABLE shift ALTER COLUMN planned_duration TYPE INTERVAL USING planned_duration * INTERVAL '60 sec'; 

但不幸的是它不起作用。我得到这个错误:

ERROR: operator does not exist: interval >= integer 
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 

你需要做什么才能正确地更改列类型并转换数据?谢谢。

+0

'SELECT * FROM移位其中planned_duration> 60 * INTERVAL '60秒” ' –

回答

1

问题是要在约束:

CONSTRAINT shift_planned_duration_check CHECK (planned_duration >= 0) 

解决去除变化塔之前该约束的问题:

ALTER TABLE shift DROP CONSTRAINT shift_planned_duration_check;