Skip to content

Instantly share code, notes, and snippets.

@LukaszWiktor
Created November 25, 2016 16:20
Show Gist options
  • Save LukaszWiktor/2e4cd881e007459f282ead00e2d37079 to your computer and use it in GitHub Desktop.
Save LukaszWiktor/2e4cd881e007459f282ead00e2d37079 to your computer and use it in GitHub Desktop.
PostrgreSQL - remove a nested JSON field if it's null
-- before: data_json = {object: {id: 123, result: null}}
-- after: data_json = {object: {id: 123}}
UPDATE events
SET data_json = data_json::jsonb #- '{object,result}'
WHERE json_typeof(data_json->'object'->'result') = 'null';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment