PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 25th, 2003, 09:30 AM
klodoma klodoma is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 klodoma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Text sort problem???

Hi too all,

I just noticed a problem at my database.

I run a query like this:
SELECT name FROM name_tbl ORDER BY name;

In the name column I have names like:
1 - "name1"
2 - "name2"
3 - " unknown";

I use " unknown" with a space at the begine so that the query returnes it as first result. ( in order 3 1 2).

I don't now what happened but the database does not sort anymore these values right(returnes 1-2-3). I noticed this today.
The sort function ignores the "special characters in the sort function".

Does anyone know why? and how to correct this?

I also have another dbserver on another machine, and on that runs well.


Thanks in advance.
Andy.

Reply With Quote
  #2  
Old November 25th, 2003, 09:37 AM
metaBarf metaBarf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 373 metaBarf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 6 sec
Reputation Power: 6
it's not really ignoring the special characters, the backend turns the string into ASCII and sorts by the ASCII code for each character. The space character, ASCII 32 I think?? is lower than any alphabet character, this is what you're seeing. Perhaps however your data is entered, you could get rid of the spaces on that end.

Reply With Quote
  #3  
Old November 25th, 2003, 09:51 AM
klodoma klodoma is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 klodoma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I looked more carefully and I noticed that it does somehow a "case insensitive" sort instead of a normal sort. Lot of words with 'a...' are after 'A...'.

I don't know what happened. Are there any settings for "case insensitive" sort?

Reply With Quote
  #4  
Old November 25th, 2003, 11:46 AM
metaBarf metaBarf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 373 metaBarf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 6 sec
Reputation Power: 6
ok, this is because A and a have different ASCII number values. A is 65, a is 97. 1 is 49. So the ordering would be 1, A, a. Does that sort of make sense? If you're using group by, order by sort then it will always use the ASCII number, not what you would always expect. your best bet is to clean the data before it is entered of special characters, or if you know it will happen with things like 1, 2, and 10 (will sort to 1, 10, 2) then you will have to do some more processing, either with your query (put it in a plpgsql procedure), or with the application performing the query and sort.

Reply With Quote
  #5  
Old November 25th, 2003, 11:51 AM
bcyde's Avatar
bcyde bcyde is offline
Me likey breadsticks...
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2003
Location: Los Angeles
Posts: 1,189 bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level)bcyde User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 1 h 12 m 58 sec
Reputation Power: 12
Send a message via AIM to bcyde Send a message via Yahoo to bcyde
Hmm, not sure if you just posted this to the Postgres mailing list but here are some possibly pertinent answers:

Quote:
"Donald Fraser" writes
PostgreSQL 7.3.x and anything below has never had case insensitive sorting
- period.


To which Tom Lane responded
Quote:
This is incorrect. In point of fact it will depend on the locale the
database is running under. I think the OP's problem is he re-initdb'd
without noting what locale setting was active.


HTH,
-b
__________________
PostgreSQL, it's what's for dinner...

Reply With Quote
  #6  
Old November 25th, 2003, 12:42 PM
klodoma klodoma is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 klodoma User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
My problem was something like this:

I give an example:

These are the datas from the table names:

id n1 n2
1 AaAa AaAa
2 X X
3 A A
4 a a
5 ab ab
6 _Y _Y
8 ..a ..a
9 .x .x
7 ...a ...a

If I run: select * from names order by n1, the result is:

id n1 n2
4 a a
8 ..a ..a
7 ...a ...a
3 A A
1 AaAa AaAa
5 ab ab
9 .x .x
2 X X
6 _Y _Y

(n1 is char(20) n2 is varchar(20)).. somehow the same.


Still now I don't know what wass the cause.

I reinstalled the db. and now works okay. I don't know if this was the only solution.

Have to search the log files. If I found something I will post it.

Best regards.
Andy.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Text sort problem???


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT