【发布时间】:2016-07-14 18:03:31
【问题描述】:
我想将数据从一列(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 字段中的值。
例如:
选择名称,名称b
之前:
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!”另一个字段的值?
【问题讨论】:
标签: sql postgresql postgresql-9.4 jsonb