Comments (11)
Null ordering has been implemented and released in v0.4.0. Did you run into issues with using the new option?
from order_query.
@glebm I am. I'm using v0.4.0. Seems like it doesn't think there are more records, even though I know there are. I did a test by COALESCE
ing the column's NULL
values to empty strings, and it seems to work.
Also, it could be because I'm using dynamic queries. I'm not sure.
from order_query.
What does the SQL look like with e.g. nulls: :last
and no COALESCE
? You can find it in the logs or by calling to_sql
on the final relation.
from order_query.
By the way, I don't mind allowing a proc as sql:
but I want to also figure out why it doesn't work for you with just nulls: :last
.
from order_query.
Interestingly, I had nulls
set to :first
, maybe that was my problem? If I set nulls
to :last
, it seems to work, but then again I'm not reaching the end of the data set.
Here is the SQL for both :first
and :last
. title
is the column that is mostly made up of NULL
values.
seek_args: [[:title, :desc, {:nulls=|:first}]]
Entry Load (1.5ms) SELECT `entries`.* FROM `entries` ORDER BY `entries`.`title` IS NULL DESC, `entries`.`title` DESC, `entries`.`id` ASC LIMIT 20
Entry Load (0.8ms) SELECT `entries`.* FROM `entries` WHERE `entries`.`id` = 1 LIMIT 1
Entry Load (1.0ms) SELECT `entries`.* FROM `entries` WHERE (`entries`.`title` IS NULL AND (`entries`.`title` IS NULL OR `entries`.`title` IS NULL AND `entries`.`id` | 1)) ORDER BY `entries`.`title` IS NULL ASC, `entries`.`title` ASC, `entries`.`id` DESC LIMIT 1
seek_args: [[:title, :desc, {:nulls=|:last}]]
Entry Load (1.0ms) SELECT `entries`.* FROM `entries` ORDER BY `entries`.`title` DESC, `entries`.`id` ASC LIMIT 20
Entry Load (0.7ms) SELECT `entries`.* FROM `entries` WHERE `entries`.`id` = 1 LIMIT 1
Entry Load (0.8ms) SELECT `entries`.* FROM `entries` WHERE (`entries`.`title` IS NOT NULL AND (`entries`.`title` IS NOT NULL OR `entries`.`title` IS NULL AND `entries`.`id` | 1)) ORDER BY `entries`.`title` ASC, `entries`.`id` DESC LIMIT 1
Let me know if I can help further.
from order_query.
What database are you using?
from order_query.
mysqld 5.7.19
from order_query.
I think I see a bug with that query. Just to confirm, what happens if you set OrderQuery.wrap_top_level_or = false
?
from order_query.
search#records_for: seek_args: [[:title, :desc, {:nulls=|:first}]]
Entry Load (1.0ms) SELECT `entries`.* FROM `entries` ORDER BY `entries`.`title` IS NULL DESC, `entries`.`title` DESC, `entries`.`id` ASC LIMIT 20
Entry Load (0.9ms) SELECT `entries`.* FROM `entries` WHERE `entries`.`id` = 1 LIMIT 1
Entry Load (2.0ms) SELECT `entries`.* FROM `entries` WHERE (`entries`.`title` IS NULL OR `entries`.`title` IS NULL AND `entries`.`id` | 1) ORDER BY `entries`.`title` IS NULL ASC, `entries`.`title` ASC, `entries`.`id` DESC LIMIT 1
(This seems to work, by the way.)
from order_query.
Thanks, I've opened a separate issue about this bug
from order_query.
(On a side note, I was not asking to add proc
support to the sql
param-- it already seems to exist. The suggestion was just to add passing in the table and column values as params to the call
.)
from order_query.
Related Issues (20)
- Ordering by NULLS FIRST / LAST HOT 10
- documentation on how to "paginate" results HOT 6
- new version release HOT 1
- Test on multiple databases
- is sorting by an associated column supported? HOT 10
- Nulls ordering skips records if there is more than one NULL HOT 6
- TODO: Better tests for nils in enums
- Change base scope? HOT 2
- Get point for reverse scope HOT 2
- Rails 6 support HOT 2
- Wrong order? HOT 1
- Top-level disjunctive causes sub-optimal query plan HOT 6
- Calling prev and next when the ordering model attribute is enumerable creates an invalid SQL where clause HOT 2
- Redundant condition elimination
- #seek or #at with previously specified order HOT 5
- Can this sort on nested attributes? HOT 3
- Feature Request: HOT 1
- .previous always showing first record when limiting scope HOT 2
- Not compatible with rails 5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from order_query.