2015-11-23 3 views
0

Ниже приведен запрос:ошибка изменяющего таблицы типа столбца в PostgreSQL - BIGINT характеру изменяющегося

alter table customer_master alter column pk_customer_id type character varying(20); 

Я получил следующее сообщение об ошибке:

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

CREATE TABLE customer_master(
    pk_customer_id bigint NOT NULL, 
    created_customer_name character varying(200) DEFAULT NULL::character varying, 
    fk_deployment_id bigint NOT NULL, 
    is_active integer 
) 

здесь pk_customer_id является первичный ключ для этой таблицы.

ответ

1

Это должно работать

USING согласно документации:

The optional USING clause specifies how to compute the new column value from the old; if omitted, the default conversion is the same as an assignment cast from old data type to new. A USING clause must be provided if there is no implicit or assignment cast from old to new type

ALTER TABLE customer_master 
ALTER COLUMN pk_customer_id type CHARACTER VARYING(20) 
USING pk_customer_id::VARCHAR; -- add using keyword 
+0

это работает для меня. Благодарю. и проблема была не только в запросе. Было ограничение, которое проверяет поле pk_customer_id> 0. поэтому при удалении ограничения он работал для меня. – siva