Skip to content

Instantly share code, notes, and snippets.

@Reimerei
Last active October 23, 2015 09:35
Show Gist options
  • Save Reimerei/9e3bf2a00b3f57e7184d to your computer and use it in GitHub Desktop.
Save Reimerei/9e3bf2a00b3f57e7184d to your computer and use it in GitHub Desktop.
Postgres jsonb: remove key from all entries
# Function
CREATE FUNCTION jsonb_merge(JSONB, JSONB)
RETURNS JSONB AS $$
WITH json_union AS (
SELECT * FROM JSONB_EACH($1)
UNION ALL
SELECT * FROM JSONB_EACH($2)
) SELECT JSON_OBJECT_AGG(key, value)::JSONB FROM json_union;
$$ LANGUAGE SQL;
# Command
Update he_user_meta set value = jsonb_merge(value, '{"game_state_version":null}');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment