[英]How do I “copy” enum values from one enum column to another enum column?
I'm trying to copy the enum values between two columns in a table.我正在尝试复制表中两列之间的枚举值。 The the two enum types have the same enum values:
这两种枚举类型具有相同的枚举值:
UPDATE dogs SET breed = breed_old;
...
ERROR: column "breed" is of type "breed" but expression is of type "breed_old"
I've also tried:我也试过:
UPDATE dogs SET breed = breed_old::text;
...
ERROR: column "breed" is of type "breed" but expression is of type text
Any help would be appreciated.任何帮助,将不胜感激。
create type foo as enum ('a','b');
create type bar as enum ('a','b');
select 'a'::foo;
┌─────┐
│ foo │
├─────┤
│ a │
└─────┘
select 'a'::foo::text;
┌──────┐
│ text │
├──────┤
│ a │
└──────┘
select 'a'::foo::text::bar;
┌─────┐
│ bar │
├─────┤
│ a │
└─────┘
Or probably more convenient:或者可能更方便:
update dogs set
breed = case breed_old
when 'val1' then 'val1'::breed
when 'val2' then 'val2'::breed
...
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.