I want to migrate data from one column (varchar) to another column (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
So that nameb
will became {"en": "$name"}
where $name
is a value in name
field.
For example:
SELECT name, nameb
before:
name | nameb
--------------------------------------+------------
hello | {}
world | {}
after:
name | nameb
--------------------------------------+------------
hello | {"en": "hello"}
world | {"en": "world"}
With regualar types I can do UPDATE SET whatever = (SELECT ...)
, but How to do this with jsonb?
UPDATE merchants SET nameb = (SELECT '{"en": "fillme!"}'::jsonb);
works, but how to set "fillme!" value from another field?