hstore to json and back again - Mailing list pgsql-general

From Paul Jungwirth
Subject hstore to json and back again
Date
Msg-id CA+6hpan3sPtLhwGbAO+VRK37KPH148CQJK0bLtrk3+-ikOaMgg@mail.gmail.com
Whole thread Raw
Responses Re: hstore to json and back again  (Paul Jungwirth <pj@illuminatedcomputing.com>)
List pgsql-general
Hello,

I'm trying to migrate an existing hstore column to json in Postgres
9.3, and I'd like to be able to run the script in reverse. I know not
all JSON can turn back into hstore, but since this is coming from an
old hstore column, I know the structure is flat (no nesting), and that
all values are strings.

Here is the SQL I'm using to go hstore -> json:

UPDATE foo
SET datahash_new = to_json(datahash_old)
;

Is there any SQL I can use to go backwards?:
UPDATE foo
SET datahash_old = xxxxx(datahash_new)
;

I understand why there is not a general-purpose solution, but in my
case this should be possible. I've tried to cook something up with
json_each_text, but I haven't been able to figure it out. Can anyone
offer any help?

Thanks,
Paul

--
_________________________________
Pulchritudo splendor veritatis.


pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: lock contention, need profiling idea
Next
From: Alex Hunsaker
Date:
Subject: Re: pl/perl and recent perl versions - failing to load internal modules