-
-
Save booo/1173513 to your computer and use it in GitHub Desktop.
hstore to json function from Ilya Kosmodemiansky
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 FUNCTION public.hs_2json(hs hstore) RETURNS text AS $$ | |
DECLARE | |
rv text; | |
r record; | |
BEGIN | |
rv:=''; | |
for r in (select key, val from each(hs) as h(key, val)) loop | |
if rv<>'' then | |
rv:=rv||','; | |
end if; | |
rv:=rv || '"' || r.key || '":'; | |
rv:=rv || '"' || r.val || '"'; | |
end loop; | |
return '{'||rv||'}'; | |
END; | |
$$ LANGUAGE plpgsql IMMUTABLE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment