Created
November 25, 2016 16:20
-
-
Save LukaszWiktor/2e4cd881e007459f282ead00e2d37079 to your computer and use it in GitHub Desktop.
PostrgreSQL - remove a nested JSON field if it's null
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
-- 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