-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 with_ties/3
to Ecto.Query
#4090
Add with_ties/3
to Ecto.Query
#4090
Conversation
Not trying to impose, just asking: have you considered making a |
@v0idpwn I did and put some discussion here:
But I'm completely open to doing a separate macro. Whatever the general consensus is for what's best. What do you and @josevalim think? edit: Oh I just saw Jose suggest this
I'm open to this as well but didn't consider it before. I can't remember if that can be used in kw queries or not. |
at the moment,
The KW queries can translate to anything we want. :D So I would keep basically the same code that you have in this PR, you would simply emit |
5d46fc8
to
f75e874
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor nits and ship it!
with_ties
option to Ecto.Query.limitwith_ties/3
to Ecto.Query
Companion ecto_sql PR: elixir-ecto/ecto_sql#471. The integration tests fail here but pass there because I was hesitant to update the earthfile.
Background
The SQL standard version of the
LIMIT
command isFETCH
. The commands are almost identical exceptFETCH
comes with an optionWITH TIES
which says that the result should include any records that are tied with the last record. For exampleLIMIT 3
might return1, 2, 3
whileFETCH 3 WITH TIES
would return1, 2, 3, 3
because 2 records have the number 3.Proposal
Add a
:with_ties
option to the currentlimit
macro. There are a few reasons I'm proposing reusing the existing macro instead of creating a newfetch
macro:FETCH
andTOP
but notLIMIT
.This proposal has a couple difficulties:
limit
was using the generic%QueryExpr{}
struct so doesn't have a place to store this new option. If we create a new struct for limits then any adapter pattern matching on%QueryExpr{}
instead of%{}
will have to be updated. All the built-in adapters had to be updated and I noticed SQLite will have to be as well.limit(query, bindings \\ [], expr, opts \\ [])
it's a little awkward specifying the option outside of keyword queries if you don't care about bindings. But this would be the case for a new macro as well.Reference
The postgres docs talk about it here: https://www.postgresql.org/docs/current/sql-select.html. It's the only built-in adapter that supports
FETCH WITH TIES
. SQL Server supportsFETCH
but notWITH TIES
option. And MySQL supports neither.