New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`DISTINCT` support #253

Closed
LordPython opened this Issue Apr 2, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@LordPython

LordPython commented Apr 2, 2016

There isn't currently support for creating SELECT DISTINCT queries.

sgrif added a commit that referenced this issue Apr 2, 2016

Add support for the `DISTINCT` keyword
A few things to note about the implementation. I've opted for 2 unit
structs instead of something like an enum or boolean so that the code
gets inlined via monomorphisation instead of containing a branch (e.g.
if you don't use distinct, it's free). As always, it's enforced that our
query builder doesn't do "real work" by
https://github.com/sgrif/diesel/blob/c8127d408f759faa056503014cd00e92479215e0/diesel_tests/tests/perf_details.rs#L8-L13

This ended up churning a lot of `select_dsl`. I've reformatted the code
surrounding what was touched to reduce churn in the future.

This doesn't yet add support for `DISTINCT ON(expr)`, as that is a PG
specific feature and can be added as a separate PR.

An alternative API for this would be something like
`users.select(distinct(name))`. I actually think I might prefer that
API, but actually enforcing correctness with it (making sure `distinct`
can only be passed to `select` and not something like `filter` --
disallowing things like `max(distinct(id))`, etc) would be pretty much
impossible.

Fixes #253.

sgrif added a commit that referenced this issue Apr 2, 2016

Add support for the `DISTINCT` keyword
A few things to note about the implementation. I've opted for 2 unit
structs instead of something like an enum or boolean so that the code
gets inlined via monomorphisation instead of containing a branch (e.g.
if you don't use distinct, it's free). As always, it's enforced that our
query builder doesn't do "real work" by
https://github.com/sgrif/diesel/blob/c8127d408f759faa056503014cd00e92479215e0/diesel_tests/tests/perf_details.rs#L8-L13

This ended up churning a lot of `select_dsl`. I've reformatted the code
surrounding what was touched to reduce churn in the future.

This doesn't yet add support for `DISTINCT ON(expr)`, as that is a PG
specific feature and can be added as a separate PR.

An alternative API for this would be something like
`users.select(distinct(name))`. I actually think I might prefer that
API, but actually enforcing correctness with it (making sure `distinct`
can only be passed to `select` and not something like `filter` --
disallowing things like `max(distinct(id))`, etc) would be pretty much
impossible.

Fixes #253.

sgrif added a commit that referenced this issue Apr 6, 2016

Add support for the `DISTINCT` keyword
A few things to note about the implementation. I've opted for 2 unit
structs instead of something like an enum or boolean so that the code
gets inlined via monomorphisation instead of containing a branch (e.g.
if you don't use distinct, it's free). As always, it's enforced that our
query builder doesn't do "real work" by
https://github.com/sgrif/diesel/blob/c8127d408f759faa056503014cd00e92479215e0/diesel_tests/tests/perf_details.rs#L8-L13

This ended up churning a lot of `select_dsl`. I've reformatted the code
surrounding what was touched to reduce churn in the future.

This doesn't yet add support for `DISTINCT ON(expr)`, as that is a PG
specific feature and can be added as a separate PR.

An alternative API for this would be something like
`users.select(distinct(name))`. I actually think I might prefer that
API, but actually enforcing correctness with it (making sure `distinct`
can only be passed to `select` and not something like `filter` --
disallowing things like `max(distinct(id))`, etc) would be pretty much
impossible.

Fixes #253.

@sgrif sgrif closed this in #255 Apr 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment