{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/1046","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/1046/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/1046/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/1046/events","html_url":"https://github.com/tgriesser/knex/pull/1046","id":115044508,"number":1046,"title":"Distinct modifier support for aggregate functions","user":{"login":"ErisDS","id":101513,"avatar_url":"https://avatars.githubusercontent.com/u/101513?v=3","gravatar_id":"","url":"https://api.github.com/users/ErisDS","html_url":"https://github.com/ErisDS","followers_url":"https://api.github.com/users/ErisDS/followers","following_url":"https://api.github.com/users/ErisDS/following{/other_user}","gists_url":"https://api.github.com/users/ErisDS/gists{/gist_id}","starred_url":"https://api.github.com/users/ErisDS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ErisDS/subscriptions","organizations_url":"https://api.github.com/users/ErisDS/orgs","repos_url":"https://api.github.com/users/ErisDS/repos","events_url":"https://api.github.com/users/ErisDS/events{/privacy}","received_events_url":"https://api.github.com/users/ErisDS/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-11-04T12:40:39Z","updated_at":"2015-11-09T23:54:38Z","closed_at":"2015-11-09T13:06:02Z","pull_request":{"url":"https://api.github.com/repos/tgriesser/knex/pulls/1046","html_url":"https://github.com/tgriesser/knex/pull/1046","diff_url":"https://github.com/tgriesser/knex/pull/1046.diff","patch_url":"https://github.com/tgriesser/knex/pull/1046.patch"},"body":"This adds support for `count(distinct *)` as discussed in #1028.\r\n\r\nI have also added support for `avg(distinct *)` and `sum(distinct *)` as both of these seemed valuable, I have not added distinct support for `min` and `max` as I don't think that adding distinct to those aggregates can impact the outcome. If it is felt that these should be added, I'm more than happy to update the PR.\r\n\r\nThere may be some confusion here between the standard distinct expression, and the distinct expression that goes inside of an aggregate function. I'm not sure whether to refer to it as 'inner distinct' or perhaps 'aggregate distinct'. When building the statement, I used `aggregateDistinct` to differ from the standard `distinct`.\r\n\r\nI should probably also rename both `_distinct()` and `_distinctFlag` to also clarify the distinction between the distincts (see what I did there? 😛) but wanted to ask if there were thoughts on the name - naming things is always the hardest part.\r\n\r\nI have tested this locally against sqlite3 only.\r\n\r\nMore than happy to provide more tests or other updates as necessary.\r\n\r\n----\r\n\r\ncloses #1028 \r\n\r\n- add support for count(distinct *), avg(distinct *) and sum(distinct *)\r\n- min and max don't really make sense with distinct, so didn't add those"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/155236901","html_url":"https://github.com/tgriesser/knex/pull/1046#issuecomment-155236901","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/1046","id":155236901,"user":{"login":"rhys-vdw","id":822105,"avatar_url":"https://avatars.githubusercontent.com/u/822105?v=3","gravatar_id":"","url":"https://api.github.com/users/rhys-vdw","html_url":"https://github.com/rhys-vdw","followers_url":"https://api.github.com/users/rhys-vdw/followers","following_url":"https://api.github.com/users/rhys-vdw/following{/other_user}","gists_url":"https://api.github.com/users/rhys-vdw/gists{/gist_id}","starred_url":"https://api.github.com/users/rhys-vdw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhys-vdw/subscriptions","organizations_url":"https://api.github.com/users/rhys-vdw/orgs","repos_url":"https://api.github.com/users/rhys-vdw/repos","events_url":"https://api.github.com/users/rhys-vdw/events{/privacy}","received_events_url":"https://api.github.com/users/rhys-vdw/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T23:54:38Z","updated_at":"2015-11-09T23:54:38Z","body":"@ErisDS That case can be addressed with an `install` script in `package.json`."}}