Re: Why do I get these results?????

From: Ragnar <gnari(at)hive(dot)is>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: Pgsql-Sql <Pgsql-sql(at)postgresql(dot)org>
Subject: Re: Why do I get these results?????
Date: 2006-03-03 09:51:17
Message-ID: 1141379477.18656.130.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On fös, 2006-03-03 at 09:50 +0100, Joost Kraaijeveld wrote:
> Hi,
>
> Why do I get the following result from the query below? I expected that,
> given the fact that there are over 100 "Jansen" (but no "jansen") in
> "Nijmegen" the first record would definitively be people living in
> "Nijmegen". If I change the order to the order that is commented out,
> the query goes OK.
>
> SELECT
> addresses.zipcode,
> addresses.city,
> addresses.housenumber,
> addresses.housenumberdetails,
> customers.lastname
> FROM prototype.customers JOIN prototype.addresses ON
> customers.contactaddress = addresses.objectid
> WHERE
> TRIM(UPPER(customers.lastname)) >= TRIM(UPPER('Jansen'))
> AND
> TRIM(UPPER(addresses.city)) >= TRIM(UPPER('NIJMEGEN'))
> ORDER BY customers.lastname, addresses.city, addresses.zipcode
> --ORDER BY addresses.city, customers.lastname, addresses.zipcode
> limit 5
>
> Result:
>
> "3089TN";"ROTTERDAM";"5";"";"jansen"
> "5712XG";"SOMEREN";"13";"";"jansen"
> "6511PS";"NIJMEGEN";"23";"";"Jansen"
> "6523RE";"NIJMEGEN";"13";"";"Jansen"
> "6524NP";"NIJMEGEN";"37";"A";"Jansen"

What LOCALE are you using?
Looks like it either sorts lowercase before uppercase
or treats them as equivalent.

Why do you not provide us with a simple test case?
Why involve a join and irrelevant columns?

What does a simple test like this do for you?:

test=# create table t (c text, n text);
CREATE TABLE
test=# insert into t values ('ROTTERDAM','jansen');
INSERT 33566780 1
test=# insert into t values ('SOMEREN','jansen');
INSERT 33566781 1
test=# insert into t values ('NIJMEGEN','Jansen');
INSERT 33566782 1
test=# insert into t values ('NIJMEGEN','Jansen');
INSERT 33566783 1
test=# insert into t values ('NIJMEGEN','Jansen');
INSERT 33566784 1
test=# select * from t ORDER BY n,c;
c | n
-----------+--------
NIJMEGEN | Jansen
NIJMEGEN | Jansen
NIJMEGEN | Jansen
ROTTERDAM | jansen
SOMEREN | jansen
(5 rows)

(this in in C locale)

gnari

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Paul Mackay 2006-03-03 10:03:24 Physical column size
Previous Message Michael Fuhr 2006-03-03 09:46:59 Re: Sequential scan where Index scan expected (update)