Search Postgresql Archives

Casting hstore to json

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

 



Hi.

I'm trying to cast hstore to json, but I don't seem to be getting a json object from hstore key/value pairs.

9.3 documentation says:
Note: The hstore extension has a cast from hstore to json, so that converted hstore values are represented as JSON objects, not as string values.
to_json(anyelement) - If the data type is not built in, and there is a cast from the type tojson, the cast function will be used to perform the conversion.

On 9.3.5 server:
db=> SELECT '"a"=>1, "b"=>2'::hstore;
       hstore       
--------------------
 "a"=>"1", "b"=>"2"
(1 row)

db=> SELECT to_json('"a"=>1, "b"=>2'::hstore);
           to_json            
------------------------------
 "\"a\"=>\"1\", \"b\"=>\"2\""
(1 row)
db=> SELECT cast(('"a"=>1, "b"=>2'::hstore) as json);
ERROR:  cannot cast type hstore to json
LINE 1: SELECT cast(('"a"=>1, "b"=>2'::hstore) as json);

Thanks!
  Pawel.


[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