Re: jsonb creation functions? - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: jsonb creation functions?
Date
Msg-id 20140801170358.GA53662@elch.exwg.net
Whole thread Raw
In response to jsonb creation functions?  (Larry White <ljw1001@gmail.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Jeff Janes
Date:
Subject: Re: Very Limited Toast Compression on JSONB (9.4 beta 2)
Next
From: Larry White
Date:
Subject: Re: Very Limited Toast Compression on JSONB (9.4 beta 2)