PosqtgreSQL string comparison
I try to compare strings in PostgreSQL.
Here are queries that I execute:
select 'UK (z'>'Ukraine';
This one returns true;
Then I try following one:
select 'UK ('>'Ukraine';
This one returns false;
I think, that 开发者_如何学编程both of these should return false , and on another PostgreSQL server it behaves correctly. But main server is producing incorrect results in such operations. What am I doing wrong?
If you are in doubt try:
SHOW lc_collate;
This will show you the default collation.
Now you can specify collation at the column level or the query level. Since your question is at the query level, you can:
select 'UK (z'::text > 'Ukraine' COLLATE "C"; -- and
select 'UK (z'::text > 'Ukraine' COLLATE "ucs_basic"; -- both return false
What's actually happening the natural language collation orders ignore whitespace and non-alphanumeric characters, so the first is whether 'UKz' > 'Ukraine' which it is, and the second is whether 'UK' is greater than 'Ukraine' which it is not.
精彩评论