{"id":4177,"date":"2025-05-09T14:43:32","date_gmt":"2025-05-09T09:13:32","guid":{"rendered":"https:\/\/www.tntra.io\/blog\/?p=4177"},"modified":"2025-05-09T15:55:01","modified_gmt":"2025-05-09T10:25:01","slug":"fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation","status":"publish","type":"post","link":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/","title":{"rendered":"Fixing Japanese Character Sorting in PostgreSQL and Ruby: A Guide to Locale Collation"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #c4161d;color:#c4161d\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #c4161d;color:#c4161d\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Problem_Use_Case_Incorrect_Sorting_of_Mixed_Japanese_and_English_Characters\" >Problem Use Case: Incorrect Sorting of Mixed Japanese and English Characters<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Solution_Setting_DB_Collation_for_Locale_Support\" >Solution: Setting DB Collation for Locale Support<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#What_is_DB_Collation\" >What is DB Collation?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Step_1_Install_Japanese_Locale_on_the_System\" >Step 1: Install Japanese Locale on the System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Step_2_Verify_Current_PostgreSQL_Collation\" >Step 2: Verify Current PostgreSQL Collation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Step_3_Update_Collation_for_Japanese_Character_Sorting\" >Step 3: Update Collation for Japanese Character Sorting<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#%E2%9A%A0%EF%B8%8F_Troubleshooting_Potential_Errors\" >\u26a0\ufe0f Troubleshooting: Potential Errors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Ruby_sort_vs_ActiveRecord_order_Understanding_the_Difference\" >Ruby .sort vs ActiveRecord .order: Understanding the Difference<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#sort_Method_in_Ruby\" >.sort Method in Ruby<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#order_Method_in_ActiveRecord\" >.order Method in ActiveRecord<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Conclusion\" >Conclusion<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#Ready_to_fix_your_sorting_issues\" >Ready to fix your sorting issues?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p>Sorting multilingual data, especially when it includes Japanese and English characters, poses unique challenges when relying on default database and language settings. By default, PostgreSQL collation settings and Ruby&#8217;s internal sort mechanisms do not handle Japanese character sorting correctly, often resulting in inconsistent or incorrect orderings across different environments.<\/p>\n\n\n\n<p>In one of our projects in Japan, we encountered this exact issue in production: Japanese and English strings of customers&#8217; names were being sorted randomly. The solution required a deep dive into database collation and understanding how Ruby\u2019s .sort compares to ActiveRecord\u2019s .order when it comes to multilingual sorting in PostgreSQL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Problem_Use_Case_Incorrect_Sorting_of_Mixed_Japanese_and_English_Characters\"><\/span>Problem Use Case: Incorrect Sorting of Mixed Japanese and English Characters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When using the default locale settings, Japanese (ja_JP) and English (en_EN) characters were not sorted correctly in our production environment. Ruby\u2019s .sort method also produced unexpected results, as it does not consider locale-aware collation. The root cause of this issue stemmed from database-level collation settings, which were not optimized for multilingual sorting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Solution_Setting_DB_Collation_for_Locale_Support\"><\/span>Solution: Setting DB Collation for Locale Support<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_DB_Collation\"><\/span>What is DB Collation?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Database collation defines how text data is sorted and compared in a database. It determines the order of characters based on language and locale rules. For example, English and Japanese have different sorting rules, and using the wrong collation can lead to incorrect ordering in queries.<\/p>\n\n\n\n<p>To correctly sort Japanese and English characters together, we need to configure PostgreSQL\u2019s collation settings. The following steps illustrate how to install and set the proper locale, and update the settings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Install_Japanese_Locale_on_the_System\"><\/span>Step 1: Install Japanese Locale on the System<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ensure that the necessary Japanese locale is installed and configured:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Dixita-Tntra\/f1a22e163246fb461e78108a3a1a84ba.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Verify_Current_PostgreSQL_Collation\"><\/span>Step 2: Verify Current PostgreSQL Collation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Run the following command to check your database\u2019s current collation settings:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Dixita-Tntra\/84d532a1c9f9a9c5ade7fee3e83260c2.js\"><\/script>\n\n\n\n<p>If it\u2019s not ja_JP.UTF-8, update your database to fix Japanese-English sorting issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Update_Collation_for_Japanese_Character_Sorting\"><\/span>Step 3: Update Collation for Japanese Character Sorting<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To modify the collation settings, follow these steps:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Dixita-Tntra\/cd6243a38e7f5324e0285f91a63a7e7a.js\"><\/script>\n\n\n\n<p>This ensures proper database collation for Japanese and English characters combined.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%9A%A0%EF%B8%8F_Troubleshooting_Potential_Errors\"><\/span>\u26a0\ufe0f Troubleshooting: Potential Errors<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In case, you face any role connection error like below\n<ul class=\"wp-block-list\">\n<li><strong>psql<\/strong>: error: connection to server on socket &#8220;\/var\/run\/postgresql\/.s.PGSQL.5432&#8221; failed: FATAL: role &#8220;username&#8221; does not exist<\/li>\n\n\n\n<li><em><strong>Solution<\/strong><\/em>: Execute above commands with prefix $ <strong>sudo -u database_username<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For such icu locale provider specific error\n<ul class=\"wp-block-list\">\n<li><strong>ERROR<\/strong>: invalid LC_COLLATE locale name: &#8220;ja_JP.utf8&#8221;<\/li>\n\n\n\n<li><strong>HINT<\/strong>: If the locale name is specific to ICU, use ICU_LOCALE.<\/li>\n\n\n\n<li><em><strong>Solution<\/strong><\/em>: Use below command instead of mentioned above to create a database as PostgreSQL 13+ gives an option of ICU locale support and not libc by default.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Dixita-Tntra\/3a67edf02b53579b91fd2bcf62539613.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Ruby_sort_vs_ActiveRecord_order_Understanding_the_Difference\"><\/span>Ruby .sort vs ActiveRecord .order: Understanding the Difference<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>After resolving collation issues at the database level, it is important to understand how Ruby handles sorting at the application level.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"sort_Method_in_Ruby\"><\/span>.sort Method in Ruby<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Ruby\u2019s .sort is used to order an array in ascending order but does not leverage database-level collation settings. Instead, it sorts using Ruby\u2019s internal comparison mechanisms.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example:<\/strong><\/h4>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Dixita-Tntra\/c5123e93f0a2047b771d610bcd4ab305.js\"><\/script>\n\n\n\n<p>The output is based on Ruby\u2019s internal string comparison, which does not always follow linguistic rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"order_Method_in_ActiveRecord\"><\/span>.order Method in ActiveRecord<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Unlike .sort, ActiveRecord\u2019s .order method sorts records at the database level using the configured collation settings.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example:<\/strong><\/h4>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Dixita-Tntra\/817afd160320b8d6be5ea8b89635b111.js\"><\/script>\n\n\n\n<p>Since .order runs at the database level, it ensures proper sorting based on the locale settings, making it the recommended approach for multilingual sorting.<\/p>\n\n\n\n<p>To configure and debug collation settings in PostgreSQL, you can also use following visual tools rather than command-line:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DBeaver<\/strong> (GUI-based database management tool)<\/li>\n\n\n\n<li><strong>pgAdmin<\/strong> (Web-based PostgreSQL management tool)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To sort Japanese characters in a database accurately, configure PostgreSQL collation with either ja_JP.UTF-8 or an ICU locale such as ja-JP. Doing this ensures consistent multilingual sorting in PostgreSQL.<\/p>\n\n\n\n<p>Also, prefer using ActiveRecord .order instead of Ruby .sort to delegate sorting responsibility to the database engine, which is now locale-aware.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Ready_to_fix_your_sorting_issues\"><\/span>Ready to fix your sorting issues?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Don\u2019t let incorrect character ordering affect your user experience. Configure PostgreSQL with the right locale and optimize your Ruby app for multilingual sorting.<\/p>\n\n\n\n<p><strong>Need help implementing locale-aware collation in your project? <a href=\"https:\/\/www.tntra.io\/contact-us\" target=\"_blank\" rel=\"noreferrer noopener\">Contact us<\/a> to talk to our experts today.<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u26a1 Bonus Tip:<\/strong><strong> <\/strong>Double-check your application\u2019s sorting logic by comparing it with Google Sheets or Excel\u2019s default sorting behaviour to spot anomalies.<\/p>\n\n\n\n<p>By setting up proper locale collation and understanding how Ruby ActiveRecord methods work, you\u2019ll resolve issues around character sorting in your application.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorting multilingual data, especially when it includes Japanese and English&#8230;<\/p>\n","protected":false},"author":13,"featured_media":4181,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-4177","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Fix Japanese Character Sorting in PostgreSQL &amp; Ruby | Locale &amp; Collation Guide Tntra<\/title>\n<meta name=\"description\" content=\"Fix Japanese and English sorting issues in PostgreSQL and Ruby using proper collation settings and ActiveRecord .order for accurate multilingual results. Learn how now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fix Japanese Character Sorting in PostgreSQL &amp; Ruby | Locale &amp; Collation Guide Tntra\" \/>\n<meta property=\"og:description\" content=\"Fix Japanese and English sorting issues in PostgreSQL and Ruby using proper collation settings and ActiveRecord .order for accurate multilingual results. Learn how now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/\" \/>\n<meta property=\"og:site_name\" content=\"Tntra\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/tntraio\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-09T09:13:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-09T10:25:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/05\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"627\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Dixita Kataria\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tntraio\" \/>\n<meta name=\"twitter:site\" content=\"@tntraio\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dixita Kataria\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/\"},\"author\":{\"name\":\"Dixita Kataria\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#\\\/schema\\\/person\\\/abb932ff801e1c65232a5ee3a50a461f\"},\"headline\":\"Fixing Japanese Character Sorting in PostgreSQL and Ruby: A Guide to Locale Collation\",\"datePublished\":\"2025-05-09T09:13:32+00:00\",\"dateModified\":\"2025-05-09T10:25:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/\"},\"wordCount\":740,\"publisher\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png\",\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/\",\"url\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/\",\"name\":\"Fix Japanese Character Sorting in PostgreSQL & Ruby | Locale & Collation Guide Tntra\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png\",\"datePublished\":\"2025-05-09T09:13:32+00:00\",\"dateModified\":\"2025-05-09T10:25:01+00:00\",\"description\":\"Fix Japanese and English sorting issues in PostgreSQL and Ruby using proper collation settings and ActiveRecord .order for accurate multilingual results. Learn how now!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png\",\"contentUrl\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png\",\"width\":1200,\"height\":627,\"caption\":\"Japanese character sorting in PostgreSQL collation settings\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fixing Japanese Character Sorting in PostgreSQL and Ruby: A Guide to Locale Collation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/\",\"name\":\"Tntra\",\"description\":\"AI-First &amp; IP-Enabled Innovation Ecosystem\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#organization\",\"name\":\"Tntra\",\"url\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/logo.png\",\"width\":300,\"height\":300,\"caption\":\"Tntra\"},\"image\":{\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/tntraio\",\"https:\\\/\\\/x.com\\\/tntraio\",\"https:\\\/\\\/www.instagram.com\\\/tntra.io\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/tntra\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/#\\\/schema\\\/person\\\/abb932ff801e1c65232a5ee3a50a461f\",\"name\":\"Dixita Kataria\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6aaed964f00044df60558c3fdd529b3740655ad29caeb97fc28cb72274f2ba00?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6aaed964f00044df60558c3fdd529b3740655ad29caeb97fc28cb72274f2ba00?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6aaed964f00044df60558c3fdd529b3740655ad29caeb97fc28cb72274f2ba00?s=96&d=mm&r=g\",\"caption\":\"Dixita Kataria\"},\"url\":\"https:\\\/\\\/www.tntra.io\\\/blog\\\/author\\\/dixita-kataria\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fix Japanese Character Sorting in PostgreSQL & Ruby | Locale & Collation Guide Tntra","description":"Fix Japanese and English sorting issues in PostgreSQL and Ruby using proper collation settings and ActiveRecord .order for accurate multilingual results. Learn how now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/","og_locale":"en_US","og_type":"article","og_title":"Fix Japanese Character Sorting in PostgreSQL & Ruby | Locale & Collation Guide Tntra","og_description":"Fix Japanese and English sorting issues in PostgreSQL and Ruby using proper collation settings and ActiveRecord .order for accurate multilingual results. Learn how now!","og_url":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/","og_site_name":"Tntra","article_publisher":"https:\/\/www.facebook.com\/tntraio","article_published_time":"2025-05-09T09:13:32+00:00","article_modified_time":"2025-05-09T10:25:01+00:00","og_image":[{"width":1200,"height":627,"url":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/05\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png","type":"image\/png"}],"author":"Dixita Kataria","twitter_card":"summary_large_image","twitter_creator":"@tntraio","twitter_site":"@tntraio","twitter_misc":{"Written by":"Dixita Kataria","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#article","isPartOf":{"@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/"},"author":{"name":"Dixita Kataria","@id":"https:\/\/www.tntra.io\/blog\/#\/schema\/person\/abb932ff801e1c65232a5ee3a50a461f"},"headline":"Fixing Japanese Character Sorting in PostgreSQL and Ruby: A Guide to Locale Collation","datePublished":"2025-05-09T09:13:32+00:00","dateModified":"2025-05-09T10:25:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/"},"wordCount":740,"publisher":{"@id":"https:\/\/www.tntra.io\/blog\/#organization"},"image":{"@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/05\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png","articleSection":["Programming"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/","url":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/","name":"Fix Japanese Character Sorting in PostgreSQL & Ruby | Locale & Collation Guide Tntra","isPartOf":{"@id":"https:\/\/www.tntra.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#primaryimage"},"image":{"@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/05\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png","datePublished":"2025-05-09T09:13:32+00:00","dateModified":"2025-05-09T10:25:01+00:00","description":"Fix Japanese and English sorting issues in PostgreSQL and Ruby using proper collation settings and ActiveRecord .order for accurate multilingual results. Learn how now!","breadcrumb":{"@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#primaryimage","url":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/05\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png","contentUrl":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/05\/fixing-japanese-character-sorting-in-postgresql-and-ruby-tntra.png","width":1200,"height":627,"caption":"Japanese character sorting in PostgreSQL collation settings"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tntra.io\/blog\/fixing-japanese-character-sorting-in-postgresql-and-ruby-a-guide-to-locale-collation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.tntra.io\/blog\/"},{"@type":"ListItem","position":2,"name":"Fixing Japanese Character Sorting in PostgreSQL and Ruby: A Guide to Locale Collation"}]},{"@type":"WebSite","@id":"https:\/\/www.tntra.io\/blog\/#website","url":"https:\/\/www.tntra.io\/blog\/","name":"Tntra","description":"AI-First &amp; IP-Enabled Innovation Ecosystem","publisher":{"@id":"https:\/\/www.tntra.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tntra.io\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.tntra.io\/blog\/#organization","name":"Tntra","url":"https:\/\/www.tntra.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.tntra.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/11\/logo.png","contentUrl":"https:\/\/www.tntra.io\/blog\/wp-content\/uploads\/2025\/11\/logo.png","width":300,"height":300,"caption":"Tntra"},"image":{"@id":"https:\/\/www.tntra.io\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/tntraio","https:\/\/x.com\/tntraio","https:\/\/www.instagram.com\/tntra.io\/","https:\/\/www.linkedin.com\/company\/tntra\/"]},{"@type":"Person","@id":"https:\/\/www.tntra.io\/blog\/#\/schema\/person\/abb932ff801e1c65232a5ee3a50a461f","name":"Dixita Kataria","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/6aaed964f00044df60558c3fdd529b3740655ad29caeb97fc28cb72274f2ba00?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6aaed964f00044df60558c3fdd529b3740655ad29caeb97fc28cb72274f2ba00?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6aaed964f00044df60558c3fdd529b3740655ad29caeb97fc28cb72274f2ba00?s=96&d=mm&r=g","caption":"Dixita Kataria"},"url":"https:\/\/www.tntra.io\/blog\/author\/dixita-kataria\/"}]}},"_links":{"self":[{"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/posts\/4177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/comments?post=4177"}],"version-history":[{"count":0,"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/posts\/4177\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/media\/4181"}],"wp:attachment":[{"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/media?parent=4177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/categories?post=4177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tntra.io\/blog\/wp-json\/wp\/v2\/tags?post=4177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}