473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

sorting and spaces in postgresql with en_US locale

We are having a weird problem that we ran into recently. If I use the
following statements to create a test table and then run the select statement
at the end, we get a very strange sort order. It appears that to do the
sorting, all the spaces are removed from the strings. It would appear that in
the example below 'ab e' should be before 'abd'.

create table testing_sort(col1 text);
insert into testing_sort values('a');
insert into testing_sort values('ab');
insert into testing_sort values('ab c');
insert into testing_sort values('abd');
insert into testing_sort values('ab e');

select * from testing_sort order by col1;
col1
------
a
ab
ab c
abd
ab e
(5 rows)

pg_controldata reports...
LC_COLLATE: en_US
LC_CTYPE: en_US

on another box, which has both LC_COLLAGE and LC_CTYPE set to C, the sorting
works as expected...

select * from testing_sort order by col1;
col1
------
a
ab
ab c
ab e
abd

Does anyone know if there is any other way to get the sorting to work as
expected short of doing an dumping, doing an initdb, and reloading? Or is
there some other setting that is causing the sort to do strange things.

The only work around we have found is to create a sort column and replace all
spaces with 0 and then sort on that column. Any other suggestions or
workarounds?

Issue was tested on both 7.4.1 and 7.3.4, both running on linux.

Thanks,

-Chris

--
Chris Kratz
Systems Analyst/Programmer
VistaShare LLC
www.vistashare.com

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
2 3721
On Wed, 2004-07-21 at 20:58, Chris Kratz wrote:
We are having a weird problem that we ran into recently. If I use the
following statements to create a test table and then run the select statement
at the end, we get a very strange sort order. It appears that to do the
sorting, all the spaces are removed from the strings. It would appear that in
the example below 'ab e' should be before 'abd'. LC_COLLATE: en_US
LC_CTYPE: en_US


That is how the en_US (and en_GB) locales are defined.

Their sorting is dictionary style: spaces and capitalisation are
ignored. This is a glibc issue, not a PostgreSQL issue.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Greater love hath no man than this, that a man lay
down his life for his friends." John 15:13
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2
Oliver Elphick wrote:
On Wed, 2004-07-21 at 20:58, Chris Kratz wrote:
We are having a weird problem that we ran into recently. If I use the
following statements to create a test table and then run the select
statement
at the end, we get a very strange sort order. It appears that to do the
sorting, all the spaces are removed from the strings. It would appear
that in the example below 'ab e' should be before 'abd'.

LC_COLLATE: en_US
LC_CTYPE: en_US


That is how the en_US (and en_GB) locales are defined.

Their sorting is dictionary style: spaces and capitalisation are
ignored. This is a glibc issue, not a PostgreSQL issue.


Is there any way to specify the collation to use for a sort, other than the
collation specified at initdb time?

For example, suppose I have a database that is running in the Foo locale,
and I have clients in the Bar locale. In the Foo locale 'Adam' sorts
before 'adam', wheras in the Bar locale 'adam' sorts before 'Adam'. Other
than doing the sort at the application level, is there any way to do this?

e.g. something like:
SELECT last_name, first_name
FROM people
ORDER BY last_name, first_name COLLATION = en_US;
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tim Edwards | last post by:
Currently I'm running PostgreSQL 7.2.3 and having a problem sorting. I've got two colums of data, one Int4 one Varchar. When I sort ASC on the varchar I get some strange results. Here a section...
12
by: Sander Smeenk | last post by:
Hi, After a very recent postgresql update, the postmaster failed to start because of this: | PANIC: The database cluster was initialized with LC_CTYPE | 'nl_NL@euro.UTF-8', which is...
1
by: CSN | last post by:
On my windows/cygwin/PG 7.3.1 box, results are sorted with lowercase appearing after uppercase. On my redhat/PG 7.3.3 boxes results are sorted without regard to case. Is there some locale (or...
2
by: Daniel Gaudreault | last post by:
One of our developers came across the fact that postgres is ignoring spaces when sorting results from a query. We are using PGSQL 7.3.4 on the backend. Is there something that needs to be set...
8
by: Hitesh Bagadiya | last post by:
Hi, Our database contains Hindi as well as English characters. We have specified the encoding to be unicode during initdb as well as createdb commands. Unfortunately sorting of the Hindi...
5
by: Dragan Matic | last post by:
If I have a table t with column c which is defined as char(5) and fill it with following values: insert into t (c) values (' 1') insert into t (c) values (' 2') insert into t (c) values...
6
by: Dennis Gearon | last post by:
This is what has to be eventually done:(as sybase, and probably others do it) http://www.ianywhere.com/whitepapers/unicode.html I'm not sure how that will affect LIKE and REGEX. ...
6
by: Jean-Guillaume LALANNE | last post by:
Hi, I am pretty new to the postgresql community. My question may seem a little bit strange but I'd like to know if it is possible to run 2 postgresql processes with 2 separate databases on the...
8
by: DierkErdmann | last post by:
Hi ! I know that this topic has been discussed in the past, but I could not find a working solution for my problem: sorting (lists of) strings containing special characters like "ä", "ü",......
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.