Discussion:
jsonb creation functions?
Larry White
2014-08-01 15:44:18 UTC
Permalink
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?

Thanks.
Christoph Moench-Tegeder
2014-08-01 17:03:59 UTC
Permalink
Hi,
Post by Larry White
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-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...