Re: jsonb creation functions?

From: Christoph Moench-Tegeder <cmt(at)burggraben(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: jsonb creation functions?
Date: 2014-08-01 17:03:59
Message-ID: 20140801170358.GA53662@elch.exwg.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Larry White 2014-08-01 17:46:05 Re: Very Limited Toast Compression on JSONB (9.4 beta 2)
Previous Message Jeff Janes 2014-08-01 16:38:40 Re: Very Limited Toast Compression on JSONB (9.4 beta 2)