Code Monkey home page Code Monkey logo

Comments (4)

davideluque avatar davideluque commented on June 14, 2024

I noticed we didn't have the correct sorting for Danish characters in our PostgreSQL database. To fix this, I used the ICU (International Components for Unicode) extension. I chose the da-DK-x-icu collation for Danish language sorting, as it's used in Denmark.

Here’s the migration I added:

class UpdateMyModelNameCollation < ActiveRecord::Migration[7.0]
  def up
    execute <<-SQL
      ALTER TABLE MyModel
      ALTER COLUMN name TYPE varchar COLLATE "da-DK-x-icu";
    SQL
  end

  def down
    execute <<-SQL
      ALTER TABLE MyModel
      ALTER COLUMN name TYPE varchar;
    SQL
  end
end

Now our system can sort Danish characters correctly.

To see the collations your PostgreSQL installation supports, run:

SELECT collname FROM pg_collation;

from ransack.

davideluque avatar davideluque commented on June 14, 2024

@scarroll32 Would this be something interesting to add to the documentation? I can only write the Postgres part or maybe just give users a lead on what could be the problem

from ransack.

scarroll32 avatar scarroll32 commented on June 14, 2024

@davideluque thank you for opening this issue, it is indeed a problem across many different languages.

Can you think of a way to make it language independent? ie: is the only way to do this in Postgres is by adding the collation?

  ALTER COLUMN name TYPE varchar COLLATE "da-DK-x-icu";

from ransack.

davideluque avatar davideluque commented on June 14, 2024

@scarroll32, database-level sorting seems to be the most efficient approach. While we could resort to Ruby's Array Sorting, it's not scalable for larger datasets.

Upon investigating collations, I found that they're specific to DBMS.

I expect this issue to guide users and I wonder if there is something else we can do to help.

from ransack.

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.