Last active
December 25, 2015 23:59
-
-
Save xwmx/7061260 to your computer and use it in GitHub Desktop.
json pl/v8 functions (not currently tested)
This file contains hidden or 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 | |
json_get(data json, prop text) RETURNS JSON as $$ | |
prop = prop.split('.'); | |
for (var i = 0, len = prop.length; i < len - 1; i++) { | |
data = data[prop[i]]; | |
} | |
return data[prop[len - 1]]; | |
$$ LANGUAGE plv8 STABLE STRICT; | |
CREATE or REPLACE FUNCTION | |
json_set(data json, prop text, value json) RETURNS JSON as $$ | |
prop = prop.split('.'); | |
for (var i = 0, len = prop.length; i < len - 1; i++) { | |
data = data[prop[i]]; | |
} | |
data[prop[len - 1]] = value; | |
return data; | |
$$ LANGUAGE plv8 STABLE STRICT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment