Created
January 31, 2012 10:10
-
-
Save kashif/1709743 to your computer and use it in GitHub Desktop.
Another hstore to JSON function by Andrew Dunstan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function hs_2json(hs hstore) returns text language sql | |
as $f$ | |
select '{' || array_to_string(array_agg( | |
'"' || regexp_replace(key,E'[\\"]',E'\\\&','g') || '":' || | |
case | |
when value is null then 'null' | |
when value ~ '^(true|false|(-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?))$' then value | |
else '"' || regexp_replace(value,E'[\\"]',E'\\\&','g') || '"' | |
end | |
),',') || '}' | |
from each($1) | |
$f$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment