Skip to content

Add support for distinct on for postgres #3472 #3513

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

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 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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 Compare November 4, 2019 04:25
@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
@kibertoad kibertoad deleted the #3472 branch November 10, 2019 23:51
@kibertoad
Copy link
Collaborator

@lorefnon Can you also add documentation for it?

victorandree added a commit to victorandree/knex that referenced this pull request Apr 7, 2020
Interface as provided by knex#3513
victorandree added a commit to victorandree/knex that referenced this pull request Apr 7, 2020
Interface as provided by knex#3513
victorandree added a commit to victorandree/knex that referenced this pull request Apr 13, 2020
Interface as provided by knex#3513
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants