{"action":"created","issue":{"url":"https://api.github.com/repos/Vincit/moron.js/issues/18","labels_url":"https://api.github.com/repos/Vincit/moron.js/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/moron.js/issues/18/comments","events_url":"https://api.github.com/repos/Vincit/moron.js/issues/18/events","html_url":"https://github.com/Vincit/moron.js/issues/18","id":94524238,"number":18,"title":"Add support for more complex syntax to compare two jsonb field references.","user":{"login":"elhigu","id":696345,"avatar_url":"https://avatars.githubusercontent.com/u/696345?v=3","gravatar_id":"","url":"https://api.github.com/users/elhigu","html_url":"https://github.com/elhigu","followers_url":"https://api.github.com/users/elhigu/followers","following_url":"https://api.github.com/users/elhigu/following{/other_user}","gists_url":"https://api.github.com/users/elhigu/gists{/gist_id}","starred_url":"https://api.github.com/users/elhigu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elhigu/subscriptions","organizations_url":"https://api.github.com/users/elhigu/orgs","repos_url":"https://api.github.com/users/elhigu/repos","events_url":"https://api.github.com/users/elhigu/events{/privacy}","received_events_url":"https://api.github.com/users/elhigu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Vincit/moron.js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-12T02:00:37Z","updated_at":"2015-08-14T20:07:47Z","closed_at":null,"body":"Currently only case where we are able to do something like \r\n```\r\nwhere (\"jsonCol\"->'a')::jsonb = (\"jsonCo\"->.'b')::jsonb\r\n``` \r\nis with equality, subset and superset operators. This case was straight forward to implement, because all those operands works nicely with `jsonb` types.\r\n\r\nTo be able to use all other operators we would need to tell explicitly casting how `jsonb` fields are interpreted for given operator.\r\n\r\ne.g. \r\n```\r\nselect * from \"ModelJson\" where (\"ModelJson\".\"jsonObject\"#>'{a}')::text LIKE (\"ModelJson\".\"jsonObject\"#>'{b}')::text;\r\n```\r\n\r\nWould require that we actually have to give type casting for both sides of operand. That is due to nature of jsonb fields where PostgreSQL just doesn't know how types should be casted, like the case is with normal columns.\r\n\r\nOne way to support type casting could be to extend filed expression a bit more to allow to tell to what type reference should be casted e.g.\r\n\r\n```javascript\r\n.whereJson(\"ModelJson.jsonObject:a.0<numeric>\", \">\", \"ModelJson.jsonObject:b.0<numeric>\")\r\n```\r\n\r\nwould yield \r\n\r\n```\r\nselect * from \"ModelJson\" where (\"ModelJson\".\"jsonObject\"#>>'{a,0}')::numeric > (\"ModelJson\".\"jsonObject\"#>>'{b,0}')::numeric;\r\n```\r\n\r\nnotice that when type casting is given, field value is extracted with `#>>` operator instead of `#>` to be able to the given casting. "},"comment":{"url":"https://api.github.com/repos/Vincit/moron.js/issues/comments/131224652","html_url":"https://github.com/Vincit/moron.js/issues/18#issuecomment-131224652","issue_url":"https://api.github.com/repos/Vincit/moron.js/issues/18","id":131224652,"user":{"login":"koskimas","id":846508,"avatar_url":"https://avatars.githubusercontent.com/u/846508?v=3","gravatar_id":"","url":"https://api.github.com/users/koskimas","html_url":"https://github.com/koskimas","followers_url":"https://api.github.com/users/koskimas/followers","following_url":"https://api.github.com/users/koskimas/following{/other_user}","gists_url":"https://api.github.com/users/koskimas/gists{/gist_id}","starred_url":"https://api.github.com/users/koskimas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koskimas/subscriptions","organizations_url":"https://api.github.com/users/koskimas/orgs","repos_url":"https://api.github.com/users/koskimas/repos","events_url":"https://api.github.com/users/koskimas/events{/privacy}","received_events_url":"https://api.github.com/users/koskimas/received_events","type":"User","site_admin":false},"created_at":"2015-08-14T20:07:47Z","updated_at":"2015-08-14T20:07:47Z","body":"How about the basic C/Java cast syntax:\r\n\r\n```js\r\n.whereJson(\"(numeric) ModelJson.jsonObject:a.0\", \">\", \"(numeric) ModelJson.jsonObject:b.0\")\r\n```"}}