Code Monkey home page Code Monkey logo

Comments (11)

glebm avatar glebm commented on May 28, 2024

Null ordering has been implemented and released in v0.4.0. Did you run into issues with using the new option?

from order_query.

twelve17 avatar twelve17 commented on May 28, 2024

@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 COALESCEing 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.

glebm avatar glebm commented on May 28, 2024

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.

glebm avatar glebm commented on May 28, 2024

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.

twelve17 avatar twelve17 commented on May 28, 2024

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.

glebm avatar glebm commented on May 28, 2024

What database are you using?

from order_query.

twelve17 avatar twelve17 commented on May 28, 2024

mysqld 5.7.19

from order_query.

glebm avatar glebm commented on May 28, 2024

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.

twelve17 avatar twelve17 commented on May 28, 2024
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.

glebm avatar glebm commented on May 28, 2024

Thanks, I've opened a separate issue about this bug

from order_query.

twelve17 avatar twelve17 commented on May 28, 2024

(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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.