dbTalk Databases Forums  

[BUGS] String Comparision Weirdness

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] String Comparision Weirdness in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tobias Brox
 
Posts: n/a

Default [BUGS] String Comparision Weirdness - 09-26-2005 , 05:18 AM






We had major problems after migrating the DB to a more powerful server; we
managed to locate the problem to a type conversion bug in our software.
Never the less, this thing puzzles us a lot:

NBTEST2=# select '-1'>'0';
?column?
----------
t
(1 row)

We've tried this query on several servers with different versions of
postgresql and different versions of glibc - some returns true, others
returns false - and it seems neither to be related to the postgresql version
nor the glibc version. At all servers we tested, strcmp("-1","0") returned
negative - at some -3 and at others -1, and not related to postgresql.

The correct result above should be false, since ascii('-')=45 while
ascii('0')=48.

Can the character set in use be significant?

--
Notice of Confidentiality: This email is sent unencrypted over the network,
and may be stored on several email servers; it can be read by third parties
as easy as a postcard. Do not rely on email for confidential information.

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Reply With Quote
  #2  
Old   
Tobias Brox
 
Posts: n/a

Default Re: [BUGS] String Comparision Weirdness - 09-26-2005 , 05:24 AM






[Tobias Brox - Mon at 12:17:33PM +0200]
Quote:
At all servers we tested, strcmp("-1","0") returned
negative - at some -3 and at others -1, and not related to postgresql.
Ehr, uncorrelated to the result of the evaluation of '-1'>'0' on postgresql,
I mean.

--
Notice of Confidentiality: This email is sent unencrypted over the network,
and may be stored on several email servers; it can be read by third parties
as easy as a postcard. Do not rely on email for confidential information.

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


Reply With Quote
  #3  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: [BUGS] String Comparision Weirdness - 09-26-2005 , 08:08 AM



On Mon, 26 Sep 2005, Tobias Brox wrote:

Quote:
We had major problems after migrating the DB to a more powerful server; we
managed to locate the problem to a type conversion bug in our software.
Never the less, this thing puzzles us a lot:

NBTEST2=# select '-1'>'0';
?column?
----------
t
(1 row)

We've tried this query on several servers with different versions of
postgresql and different versions of glibc - some returns true, others
returns false - and it seems neither to be related to the postgresql version
nor the glibc version. At all servers we tested, strcmp("-1","0") returned
negative - at some -3 and at others -1, and not related to postgresql.

The correct result above should be false, since ascii('-')=45 while
ascii('0')=48.

Can the character set in use be significant?
It's more likely to be the locale in use. For example, on my machine,
given a file with -1 and 0.

LANG="C" sort file
-1
0

LANG="en_US" sort file
0
-1

Many locales do a more complicated comparison than ascii values (like
strcmp). For example, symbols and spaces may only be used as tiebreakers
after effectively comparing the strings without them.


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #4  
Old   
Tobias Brox
 
Posts: n/a

Default Re: [BUGS] String Comparision Weirdness - 09-26-2005 , 02:45 PM



[Stephan Szabo - Mon at 06:07:48AM -0700]
Quote:
It's more likely to be the locale in use. For example, on my machine,
given a file with -1 and 0.
(...)
LANG="en_US" sort file
0
-1
Hah, those Americans don't even know how to count ;-)

I find this weird, but it's clearly not a problem with postgresql at least.
We should obviously check up the locale and stick to "C" on the servers.

Thanks for the effort.

--
Notice of Confidentiality: This email is sent unencrypted over the network,
and may be stored on several email servers; it can be read by third parties
as easy as a postcard. Do not rely on email for confidential information.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.