我想将数据从一个列(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
之前:
name | nameb
--------------------------------------+------------
hello | {}
world | {}
之后:
name | nameb
--------------------------------------+------------
hello | {"en": "hello"}
world | {"en": "world"}
对于常规类型,我可以使用 UPDATE SET whatever = (SELECT ...)
,但是如何在jsonb中实现呢?
UPDATE merchants SET nameb = (SELECT '{"en": "fillme!"}'::jsonb);
是可行的,但是如何从另一个字段设置 "fillme!" 的值呢?