Search Postgresql Archives

Re: jsonb creation functions?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux