Hi,

> There is a set of creation functions for json, such as:
> 
>  to_json(anyelement)
> 
> There doesn't seem to be any equivalent functions for converting text to
> jsonb.
> 
> Is there a way to do this?

You can always cast json to jsonb:
test_db=# create table t (a integer primary key, b jsonb);
CREATE TABLE
test_db=# insert into t (a, b) values (1, to_json('a'::text)::jsonb);
INSERT 0 1
test_db=# select * from t;
 a |  b  
---+-----
 1 | "a"
(1 row)

test_db=# insert into t (a, b) values (2, 
to_json('{"a","b","c"}'::text[])::jsonb);
INSERT 0 1
test_db=# select * from t;
 a |        b        
---+-----------------
 1 | "a"
 2 | ["a", "b", "c"]
(2 rows)

Regards,
Christoph

-- 
Spare Space


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to