Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION "json_object_set_key"(
- "json" json,
- "key_to_set" TEXT,
- "value_to_set" anyelement
- )
- RETURNS json
- LANGUAGE sql
- IMMUTABLE
- STRICT
- AS $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$;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement