Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5984001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:18:42+00:00 2026-05-22T22:18:42+00:00

I want to sort by rating DESC. It works with MySQL but on PostgreSQL.

  • 0

I want to sort by rating DESC. It works with MySQL but on PostgreSQL. I get a different result.

You can see the problem here: http://www.vinderhimlen.dk/konkurrencer

My controller:

  def sort_column
    Konkurrancer.column_names.include?(params[:sort]) ? params[:sort] : "rating"
  end

  def sort_direction
    %w[desc asc].include?(params[:direction]) ? params[:direction] : "desc"
  end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:18:43+00:00Added an answer on May 22, 2026 at 10:18 pm

    Not sure what your issue is exactly or how it “doesn’t work”, from lack of details in your question. But at least two factors can affect sorting in such a way that you’d get different results in MySQL and PostgreSQL.

    The first is collation. In particular if you’re playing with 9.1 beta. Last I installed MySQL (which was a while ago, so they might have fixed this since), it was collating things as latin-1/swedish by default, vs utf-8/english for PostgreSQL.

    The other is nulls. MySQL always places these last if memory serves. By contrast, PostgreSQL consistently places them at the end of btree indexes, and thus places them last when ordering asc and first when ordering desc. You can change this behavior by ordering using nulls first/nulls last.

    In your particular case, my guess is that you want to order by rating desc nulls last, as opposed to the default behavior which will place nulls first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the default sorting to be rating DESC, but I also have, some
I want to sort the array c. But I don't get the answer a,b,c,d.
I want to sort ListView items by the content of second column (which can
I want to sort a list of integer values, but before sorting them I
I want to sort an array by 'hits', but I also want to look
i want to sort dictionary based upon value of each dictioanry item.but if i
I want to sort a bunch of files. I can do sort file.txt >
I want to sort my lucene(.net) search results by a date field (date1), but
Every picture has a rating from 1 to 5. I want to sort them
I want to sort sprites by layer depth (i.e. SpriteSortMode.BackToFront) but also sort them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.