为什么我不能将列从一个枚举转换为另一个枚举?
鉴于此设置,
create type myenum_one as enum('foo', 'bar', 'baz');
create table mytable (
myvalue myenum_one
);
alter table mytable
add constraint mycheckconstraint check (myvalue != 'bar');
insert into mytable values ('foo');
create type myenum_two as enum('foo', 'bar');
当尝试更改列类型时,它会失败
alter table mytable
alter column myvalue type myenum_two using myvalue::text::myenum_two;
并出现错误
错误:运算符不存在:enum_two <>枚举_one
提示:没有运算符与给定名称和参数类型匹配。您可能需要添加显式类型转换。
Given this setup
create type myenum_one as enum('foo', 'bar', 'baz');
create table mytable (
myvalue myenum_one
);
alter table mytable
add constraint mycheckconstraint check (myvalue != 'bar');
insert into mytable values ('foo');
create type myenum_two as enum('foo', 'bar');
It then fails on when trying to alter the column type
alter table mytable
alter column myvalue type myenum_two using myvalue::text::myenum_two;
With error
ERROR: operator does not exist: enum_two <> enum_one
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在更改列类型之前删除支票约束,然后在此之后重新创建(如果仍然相关),例如
You need to drop the check constraint before altering the column type, and the recreate it after (if it's still relevant), like so