-
Notifications
You must be signed in to change notification settings - Fork 368
Distinct and OrderBy Unindexed field #269
Comments
Additionally, when in a join, await db
.select(lf.fn.distinct(table.id))
.from(table, secondTable)
.where(secondTable.parentId.eq(table.id))
.orderBy(secondTable.id, lf.Order.ASC)
.limit(10)
.exec(); This will yield the same result as when ordering by |
Could you post the code that registers the db schema? Can you verify that
That sounds pretty interesting. Do you need to use distinct() though, if table.id is already unique (I assume?). Either way, does an equivalent query in SQLlite returns the results you expect? |
Well, I just dug a little deeper into this, and here is what I have found:
https://codepen.io/s-flhti/pen/mdEebgP I am wondering what would happen when it is sorted by an aggregated function on a await db
.select(table.id)
.from(table, table2)
.where(table2.parentId.eq(table.id))
.groupBy(table2.parentId)
.orderBy(lf.fn.min(table2.integerField), lf.Order.ASC)
.limit(10)
.exec(); But that's another discussion. EDIT
yes
yes, I have a Typescript wrapper on top of LoveFields and it is strongly typed to the interfaces I have, so I can't really make a mistake like this. Unless I explicitly cast the value to
Well, it is complicated. I don't really need to use distinct on
So both these two limitations are apparently only applicable to Lovefield and SQLite has no such rules and limitations regarding distinct and indexes, or distinct and inner join. Tested with https://sqliteonline.com/ with this data: |
Date
A simple query as follow works great:
or even by an string field:
But ordering by date doesn't work in my case:
By not working I mean it gives me a result that doesn't change if I modify the order to
DESC
orASC
. It just returns a static result as if the date created is zero or the same number for all rows. Checked manually and each row does in fact have a different value.Removing the
distinct
function fixes the problem.If you need any additional information, please ask.
The text was updated successfully, but these errors were encountered: