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
Request for distinctOn Method #3472
Comments
Sounds fine to me... If the method is called with any other DB (not supporting it) error should be thrown, Anyone... feel free to implement and send PR for this 👍 |
Released in 0.20.2 |
Hi @kibertoad , i updated my knex version to 0.20.2, but i still cant use distinctOn. Do i have to call the method like this? knex('table1').distinctOn('columnA'). |
@jsilveira2 Can you please provide an example of how you are using it ? |
@lorefnon Yes of course, thanks for answer. My complete query:
I using after select, but i try before and the same error is returned. My final query have to be like this:
Sorry for my bad english. |
How does this function work, i cant find |
Environment
Knex version: 0.19.5
Database + version: PostgreSQL v11.5
OS: MacOS
Feature discussion / request
Background
This is about adding a
distinctOn
method to Knex, in addition to the existingdistinct
. This has been previously discussed in these issues: #51, #681.Use Case
As mentioned in the above referenced issues, it's currently possible to use
DISTINCT ON
throughraw
, but there are some problems with this.,
after the clause which is invalid in PostgreSQL and causes the query to fail. For example it will turn out looking likeselect distinct on ("column1"), "column2" from "tbl_name"
.raw
, the query would no longer be reusable if additional selects needed to be added because Knex will append the select with a comma.knex('table').select(knex.raw('distinct on (??) ??', ['id', 'id']))
. The problem with this is the possibility for duplicate columns in select.What would support this?
A
distinctOn
function that would keep thedistinct on
portion separate from otherselect
's.API Proposal
Resulting in
The text was updated successfully, but these errors were encountered: