{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/4706","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/4706/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/4706/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/4706/events","html_url":"https://github.com/sequelize/sequelize/pull/4706","id":112781846,"number":4706,"title":"pg range handling improved","user":{"login":"alekbarszczewski","id":2742373,"avatar_url":"https://avatars.githubusercontent.com/u/2742373?v=3","gravatar_id":"","url":"https://api.github.com/users/alekbarszczewski","html_url":"https://github.com/alekbarszczewski","followers_url":"https://api.github.com/users/alekbarszczewski/followers","following_url":"https://api.github.com/users/alekbarszczewski/following{/other_user}","gists_url":"https://api.github.com/users/alekbarszczewski/gists{/gist_id}","starred_url":"https://api.github.com/users/alekbarszczewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alekbarszczewski/subscriptions","organizations_url":"https://api.github.com/users/alekbarszczewski/orgs","repos_url":"https://api.github.com/users/alekbarszczewski/repos","events_url":"https://api.github.com/users/alekbarszczewski/events{/privacy}","received_events_url":"https://api.github.com/users/alekbarszczewski/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sequelize/sequelize/labels/postgres","name":"postgres","color":"006b75"}],"state":"open","locked":false,"assignee":{"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},"milestone":null,"comments":10,"created_at":"2015-10-22T11:22:24Z","updated_at":"2015-11-10T13:50:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/sequelize/sequelize/pulls/4706","html_url":"https://github.com/sequelize/sequelize/pull/4706","diff_url":"https://github.com/sequelize/sequelize/pull/4706.diff","patch_url":"https://github.com/sequelize/sequelize/pull/4706.patch"},"body":"@janmeier @mickhansen I've improved pg ranges to handle unbound ranges, +/-infinity bounds and empty ranges:\r\n\r\n```js\r\nrange.stringify([]) == 'empty'\r\nrange.stringify([null, 1]) == '(,1)'\r\nrange.stringify([1, null]) == '(1,)'\r\nrange.stringify([null, null]) == '(,)'\r\nrange.stringify([-Infinity, 10]) == '(-infinity,10)'\r\nrange.stringify([-Infinity, Infinity]) == '(-infinity,infinity)'\r\n\r\nrange.parse('empty', 'int4range') == [] // inclusive: []\r\nrange.parse('(,1)', 'int4range') == [null, 1] // inclusive: [false, false]\r\nrange.parse('(1,)', 'int4range') == [1, null] // inclusive: [false, false]\r\nrange.parse('(,)', 'int4range') == [null, null] // inclusive: [false, false]\r\nrange.parse('(-infinity,10)', 'int4range') == [-Infinity, 10] // inclusive: [false, false]\r\nrange.parse('(-infinity,infinity)', 'int4range') == [-Infinity, Infinity] // inclusive: [false, false]\r\n```\r\n\r\nI've also added/modified proper tests. However there is one thing I am not sure of - before my PR if any bound in an array was null or passed range was not an array at all, then `range.stringify()` returned empty string, which is not a valid PG range literal and caused PG error `ERROR:  malformed range literal: \"\"`. I am not sure if it is bug or intensional, but I partially left this behaviour:\r\n\r\n```js\r\nfunction stringify (data) {\r\n  if (data === null) return null;\r\n  if (!Utils._.isArray(data)) return ''; // will throw error, since '' is not a valid PG range literal\r\n  if (!data.length) return 'empty';\r\n  if (data.length !== 2) return ''; // will throw error, since '' is not a valid PG range literal\r\n  ...\r\n```\r\nSo if range is not an array OR it's not empty array (which means empty range) OR range.length is not 2 then it will throw error as I described above. It could stay as is, but maybe it would be good idea to throw some validation error here instead of leaving this for postgres?"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/155424647","html_url":"https://github.com/sequelize/sequelize/pull/4706#issuecomment-155424647","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/4706","id":155424647,"user":{"login":"alekbarszczewski","id":2742373,"avatar_url":"https://avatars.githubusercontent.com/u/2742373?v=3","gravatar_id":"","url":"https://api.github.com/users/alekbarszczewski","html_url":"https://github.com/alekbarszczewski","followers_url":"https://api.github.com/users/alekbarszczewski/followers","following_url":"https://api.github.com/users/alekbarszczewski/following{/other_user}","gists_url":"https://api.github.com/users/alekbarszczewski/gists{/gist_id}","starred_url":"https://api.github.com/users/alekbarszczewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alekbarszczewski/subscriptions","organizations_url":"https://api.github.com/users/alekbarszczewski/orgs","repos_url":"https://api.github.com/users/alekbarszczewski/repos","events_url":"https://api.github.com/users/alekbarszczewski/events{/privacy}","received_events_url":"https://api.github.com/users/alekbarszczewski/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T13:50:17Z","updated_at":"2015-11-10T13:50:17Z","body":"@janmeier Thanks for info, but it seems that my tests are still passing, only MariaDB tests failed (I guess they will pass after rerunning the build). Right now it works like this:\r\n\r\n```\r\nmodel.set('range', [null, null]) -> '(,)' -> model.get('range') -> [null, null] -> stringify() -> [null, null]\r\nmodel.set('range', [-Infinity, Infinity]) -> '(-infinity,infinity)' -> model.get('range') -> [-Infinity, Infinity] -> stringify() -> [null, null]\r\n```\r\n\r\nYou think we can leave it as is? It will work on server side, but user will have to handle `Infinity -> 'infinity'` stringification and parsing on his own."}}