kromm77 icon

Untitled

kromm77 | PRO | 03/21/16 03:48:14 PM UTC | 0 ⭐ | 490 👁️ | Never ⏰ | []
text |

550 B

|

None

|

0 👍

/

0 👎

--http://stackoverflow.com/questions/18209625/how-do-i-modify-fields-inside-the-new-postgresql-json-datatype CREATE OR REPLACE FUNCTION "json_object_set_key"(  "json"          json,  "key_to_set"    TEXT,  "value_to_set"  anyelement)  RETURNS json  LANGUAGE sql  IMMUTABLE  STRICTAS $function$SELECT concat('{', string_agg(to_json("key") || ':' || "value", ','), '}')::json  FROM (SELECT *          FROM json_each("json")         WHERE "key" <> "key_to_set"         UNION ALL        SELECT "key_to_set", to_json("value_to_set")) AS "fields"$function$;

Comments