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 7539559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:24:56+00:00 2026-05-30T07:24:56+00:00

In a simple comparison test in postgres 9.1 and 8.4 is get the following

  • 0

In a simple comparison test in postgres 9.1 and 8.4 is get the following weird results.

postgres=# select 1 one where 'A' < 'a';
 one 
-----
(0 rows)    // ..... I would have expected 1 row

postgres=# select 1 one where 'A' < 'b';
 one 
-----
   1
(1 row)    // ...... this looks OK

postgres=# select 1 one where 'A' = 'a';
 one 
-----
(0 rows)   // ...... This also looks OK

postgres=# select 1 one where 'A' > 'a';
 one 
-----
   1
(1 row)    // ...... This is inconsistent with the above results

The ascii value of ‘A’ is 0x41 and ‘a’ is 0x61 so a straight comparison of ascii values should mean that ‘A’ is smaller than ‘a’, or if some case insentive magic then at least A>b and Alocale problem, but then again — however my local is set to a standard us_EN.utf8 setting using a standard Centos5 and Fedora16 installations with same results.

Attaching a debugger to the postgres process, I have been able to track down that the problem comes from that;

strcoll("A","a") returns 6;

where

strcoll("A","b") returns -1;

However this can only be demonstrated from inside the postgres process (such as when attaching gdb), and an external program like the one below gives perfectly reasonable results.

main()
{
    char *a="a";
    char *b="b";
    char *A="A";

    printf("%s\n",setlocale(2,"us_ENG.utf8"));

    printf("%d\n",strcoll(A,a));
    printf("%d\n",strcoll(A,b));
    printf("%d\n",strcoll(a,a));
    printf("%d\n",strcoll(b,b));

    printf("%d\n",strcoll(a,A));
    printf("%d\n",strcoll(b,A));
    printf("%d\n",strcoll(b,a));
    printf("%d\n",strcoll(A,A));
}

Question is: does anybody have any idea as to what would cause strcoll to return bad values, and any suggestion as how to fix it so my sample SQL will work correctly.

Update: I tried to recreate the database as initdb --locale=C, and the ‘A'<‘a’ give expected results there — however that does not explain why this fails in a database created as UTF-8.

  • 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-30T07:24:58+00:00Added an answer on May 30, 2026 at 7:24 am

    Ordering depends on your database locale, not system locale. (Though it should be noted that PostgreSQL relies on the OS to provide specifics. More in the Postgres Wiki.)
    The ASCII value is only relevant with the non-locale "C".

    Take a look at your current settings:

    SELECT * FROM pg_settings WHERE name ~~ 'lc%';
    

    In particular, the setting for LC_COLLATE is relevant. You can also:

    SHOW lc_collate;
    

    In PostgreSQL 9.1 you can change the applicable collation per statement. Try:

    SELECT 1 AS one WHERE 'A' < 'a' COLLATE "C";
    

    In older versions you are (mostly) stuck with the value for LC_COLLATE that you chose when creating your database cluster.

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

Sidebar

Related Questions

I am looking for a fairly simple image comparison method in AS3. I have
I can not get to make this comparison in this simple code error ..
I have an Sqlite database in which I want to select rows of which
I have the results of a test taken by a number of individuals at
my Ruby On Rails unit-test fails in a simple string comparison and I can't
I've seen second one in another's code and I suppose this length comparison have
I have the following query: ;WITH valRules AS ( SELECT vr.valRuleID, Count(*) AS totalRows,
I am creating a simple comparison script and I have some questions for the
When I call this template I get the following results. 155IT Matches 155OO 155OO
I have just run a very simple JavaScript performance test (don't ask why). The

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.