postgresql 如何基于条件重命名一列中的值,而保留其他值?

a7qyws3x  于 2023-01-25  发布在  PostgreSQL
关注(0)|答案(1)|浏览(105)

使用SQL,我如何根据条件重命名一列中的值,并保留其他值?
我试过了

select a, b,
  case when a = 'specific value' then 'new_value'
  else a -- keep the current value for anything else
  end as c
from x;

错误:枚举"new_value"的输入值无效
与更新数据库列无关,只返回select语句

hs1ihplo

hs1ihplo1#

select a, b,
  case when a = 'specific value' then cast('new_value' as text)
  else cast(a as text) -- keep the current value for anything else
  end as c
from x;

相关问题