{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/4692","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/4692/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/4692/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/4692/events","html_url":"https://github.com/sequelize/sequelize/issues/4692","id":112404133,"number":4692,"title":"Delete JSONB property (with PostgreSQL)","user":{"login":"pensierinmusica","id":3594037,"avatar_url":"https://avatars.githubusercontent.com/u/3594037?v=3","gravatar_id":"","url":"https://api.github.com/users/pensierinmusica","html_url":"https://github.com/pensierinmusica","followers_url":"https://api.github.com/users/pensierinmusica/followers","following_url":"https://api.github.com/users/pensierinmusica/following{/other_user}","gists_url":"https://api.github.com/users/pensierinmusica/gists{/gist_id}","starred_url":"https://api.github.com/users/pensierinmusica/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pensierinmusica/subscriptions","organizations_url":"https://api.github.com/users/pensierinmusica/orgs","repos_url":"https://api.github.com/users/pensierinmusica/repos","events_url":"https://api.github.com/users/pensierinmusica/events{/privacy}","received_events_url":"https://api.github.com/users/pensierinmusica/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-20T16:08:32Z","updated_at":"2015-10-20T16:21:12Z","closed_at":null,"body":"Hi,\r\n\r\nI'm using sequelize (v3.12.2), with pg (4.4.3), PostgreSQL (v9.4), and Node (v4.1.2).\r\n\r\nI have a model that inlcudes a JSONB data type field.\r\n```js\r\nvar User = {\r\n  data: {\r\n    type: Sequelize.JSONB\r\n}\r\n```\r\n\r\nNow I can do\r\n```js\r\nUser.findOne({where: {id: 12345}})\r\n  .update({data: {x: 'foo'}});\r\n```\r\n\r\nAnd\r\n```js\r\nUser.findOne({where: {id: 12345}})\r\n  .update({'data.y': 'bar'});\r\n```\r\n\r\nNow, if I want to delete just the `data.x` property how can I do it in one command?\r\n```js\r\nUser.findOne({where: {id: 12345}})\r\n  .update({'data.x': null});\r\n```\r\n\r\nObviously doesn't work. In fact, the resulting data object should be:\r\n```js\r\n{y: 'bar'}\r\n```\r\n\r\nAnd not:\r\n```js\r\n{x: null, y: 'bar'}\r\n```\r\n\r\nHow can I do this with Sequelize? Thanks for your help!"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/149621245","html_url":"https://github.com/sequelize/sequelize/issues/4692#issuecomment-149621245","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/4692","id":149621245,"user":{"login":"janmeier","id":1210224,"avatar_url":"https://avatars.githubusercontent.com/u/1210224?v=3","gravatar_id":"","url":"https://api.github.com/users/janmeier","html_url":"https://github.com/janmeier","followers_url":"https://api.github.com/users/janmeier/followers","following_url":"https://api.github.com/users/janmeier/following{/other_user}","gists_url":"https://api.github.com/users/janmeier/gists{/gist_id}","starred_url":"https://api.github.com/users/janmeier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janmeier/subscriptions","organizations_url":"https://api.github.com/users/janmeier/orgs","repos_url":"https://api.github.com/users/janmeier/repos","events_url":"https://api.github.com/users/janmeier/events{/privacy}","received_events_url":"https://api.github.com/users/janmeier/received_events","type":"User","site_admin":false},"created_at":"2015-10-20T16:21:12Z","updated_at":"2015-10-20T16:21:12Z","body":"Not possible currently, but seems the syntax for pg 9.5 is \r\n\r\n> jsonb - text, which can be used to remove in a jsonb field a given key at the top-level of the field (no nested operations possible here).\r\n\r\n```\r\n=# SELECT '{\"a1\":\"v1\",\"a2\":\"v2\"}'::jsonb - 'a1' AS field;\r\n     field\r\n--------------\r\n {\"a2\": \"v2\"}\r\n(1 row)\r\n```\r\nhttp://michael.otacoo.com/postgresql-2/postgres-9-5-feature-highlight-new-jsonb-functions/\r\n\r\nFor older pg versions you have to create a function that loops through the object and removes the unwanted keys - ugly!! http://stackoverflow.com/questions/23490965/postgresql-remove-attribute-from-json-column"}}