如何 "copy" 从一个枚举列到另一个枚举列枚举值?
How do I "copy" enum values from one enum column to another enum column?
我正在尝试复制 table 中两列之间的枚举值。这两个枚举类型具有相同的枚举值:
UPDATE dogs SET breed = breed_old;
...
ERROR: column "breed" is of type "breed" but expression is of type "breed_old"
我也试过:
UPDATE dogs SET breed = breed_old::text;
...
ERROR: column "breed" is of type "breed" but expression is of type text
如有任何帮助,我们将不胜感激。
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 │
└─────┘
或者可能更方便:
update dogs set
breed = case breed_old
when 'val1' then 'val1'::breed
when 'val2' then 'val2'::breed
...
end;
我正在尝试复制 table 中两列之间的枚举值。这两个枚举类型具有相同的枚举值:
UPDATE dogs SET breed = breed_old;
...
ERROR: column "breed" is of type "breed" but expression is of type "breed_old"
我也试过:
UPDATE dogs SET breed = breed_old::text;
...
ERROR: column "breed" is of type "breed" but expression is of type text
如有任何帮助,我们将不胜感激。
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 │
└─────┘
或者可能更方便:
update dogs set
breed = case breed_old
when 'val1' then 'val1'::breed
when 'val2' then 'val2'::breed
...
end;