A script in Python didn’t work, and I reduced the problem to what follows.
In PostgreSQL 9.1 I tried:
SELECT 'P 0' < 'P! '
f
And in Python 2.7.3:
>>> 'P 0' < 'P! '
True
Why is ' ' not lower than '!' in PostgreSQL? What is happening?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
PostgreSQL is using your locale’s collation rules for string comparison. Python is using a different locale (possibly “C”) for collation.
It’s hard to say more without knowing what your database
LC_COLLATEis (from\l+inpsql) and what your runtime environment for Python is. Try showing the database locale and the output of the shelllocalecommand.See the PostgreSQL documentation on locales.
For example, compare and contrast: