Skip to content
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

Add support for distinct on for postgres #3472 #3513

Merged
merged 1 commit into from Nov 10, 2019
Merged

Add support for distinct on for postgres #3472 #3513

merged 1 commit into from Nov 10, 2019

Conversation

@lorefnon
Copy link
Collaborator

lorefnon commented Nov 3, 2019

No description provided.

@@ -574,6 +578,12 @@ assign(QueryCompiler.prototype, {
);
},

distinctOn(value) {
throw new Error(
'.distinctOn() is currently only supported on PostgreSQL'

This comment has been minimized.

Copy link
@kibertoad

kibertoad Nov 3, 2019

Collaborator

How difficult would it be to support equivalent MySQL syntax? https://stackoverflow.com/questions/17673457/converting-select-distinct-on-queries-from-postgresql-to-mysql

Also does that also work on redshift?

This comment has been minimized.

Copy link
@lorefnon

lorefnon Nov 4, 2019

Author Collaborator

@kibertoad I don't think it is a very good idea to emulate this feature in Knex because:

  1. It introduces more complexity (both in implementation, and affects runtime performance)
  2. I don't see a straightforward emulation that is generically applicable

For instance, consider the last example in that answer, if we add one more column (col5) to the order by then the solution will need more modification because we would need to find the minimum of col5 among all rows that have same value of col4 potentially introducing another level of nesting.

Redshift doesn't support distinct on either.

@lorefnon lorefnon force-pushed the #3472 branch 2 times, most recently from 6142b74 to 5a4a12c Nov 4, 2019
Resolves #3472
@lorefnon lorefnon force-pushed the #3472 branch from 5a4a12c to 0db497b Nov 4, 2019
@lorefnon lorefnon changed the title WIP: #3472 Add support for distinct on for postgres Add support for distinct on for postgres #3472 Nov 5, 2019
@kibertoad kibertoad merged commit f87b28c into master Nov 10, 2019
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@kibertoad kibertoad deleted the #3472 branch Nov 10, 2019
@kibertoad

This comment has been minimized.

Copy link
Collaborator

kibertoad commented Nov 10, 2019

@lorefnon Can you also add documentation for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.