From: | Pawel Veselov <pawel(dot)veselov(at)gmail(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Casting hstore to json |
Date: | 2015-01-16 03:59:09 |
Message-ID: | CAMnJ+Bdt9NCNnJeFvp-dHXF4wk0O_YZ5ExRqCSd5zau3hY3tfA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
<http://www.postgresql.org/docs/9.3/static/hstore.html> 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Sameer Kumar | 2015-01-16 04:16:28 | Re: Check that streaming replica received all data after master shutdown |
Previous Message | Fabio Ugo Venchiarutti | 2015-01-16 02:41:05 | Re: Proper use of pg_xlog_location_diff() |