我想将数据从一列(varchar)迁移到另一列(jsonb)
Column | Type | Modifiers
------------+-----------------------------+--------------------------------------------------------
id | integer | not null default nextval('merchants_id_seq'::regclass)
name | character varying | not null
nameb | jsonb | not null default '{}'::jsonb
因此 nameb
将成为 {"en": "$name"}
,其中 $name
是 name
字段中的值 .
例如:
SELECT name,nameb
before:
name | nameb
--------------------------------------+------------
hello | {}
world | {}
after:
name | nameb
--------------------------------------+------------
hello | {"en": "hello"}
world | {"en": "world"}
使用regualar类型我可以做 UPDATE SET whatever = (SELECT ...)
,但如何用jsonb做到这一点?
UPDATE merchants SET nameb = (SELECT '{"en": "fillme!"}'::jsonb);
有效,但如何从另一个字段设置"fillme!"值?
1 回答
我找到了解决方案
不确定它是否正确,但它确实有效