Postgresql 在CASE语句中更新jsonb列:";列的类型为jsonb,但表达式的类型为“text”;
我在博士后11.4班工作。我有一个带有jsonb列的表:Postgresql 在CASE语句中更新jsonb列:";列的类型为jsonb,但表达式的类型为“text”;,postgresql,Postgresql,我在博士后11.4班工作。我有一个带有jsonb列的表: Table "public.feature_bundle_plan_feature" Column | Type | Collation | Nullable | Default -------------------+-----------------------------+-----------+----
Table "public.feature_bundle_plan_feature"
Column | Type | Collation | Nullable | Default
-------------------+-----------------------------+-----------+----------+---------------
plan_feature_id | integer | | not null |
feature_bundle_id | integer | | not null |
value | jsonb | | | 'true'::jsonb
我可以将对象直接存储在jsonbvalue
列中,如下所示:
insert into feature_bundle_plan_feature(plan_feature_id, feature_bundle_id, value)
values(1, 1, '{"foo":"bar"}');
但是,我似乎无法在案例中执行相同的操作
语句:
update feature_bundle_plan_feature set value = case
when feature_bundle_id=1 then '{"foo":"bar"}'
end;
这在以下情况下失败:
ERROR: column "value" is of type jsonb but expression is of type text
LINE 1: update feature_bundle_plan_feature set value = case
HINT: You will need to rewrite or cast the expression.
我做错了什么?错误消息是什么:
'{“foo”:“bar”}::jsonb
{code>'{“foo”:“bar”}'不是有效的JSON。@stickybit抱歉,已经纠正了打字错误,仍然会出现相同的错误消息。@a_horse_,没有名字,谢谢,这很有效@一匹没有名字的马很好奇为什么我需要在CASE
子句中插入时转换为::jsonb
,但不是别的?