Re: Ordering by field using lower()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: speedboy <speedboy(at)nomicrosoft(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Ordering by field using lower()
Date: 2001-10-14 05:16:27
Message-ID: 26143.1003036587@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

speedboy <speedboy(at)nomicrosoft(dot)org> writes:
> Hi, please view the output from some queries below. My question is, why is
> the ordering apparently wrong when using the lower() function?

You're getting a textual sort, not a numeric sort.

> The field "pid" is of type int2 and there is no need to use lower(), but I
> will need to put a test clause in php if my order type is pid so I do not
> use lower() in the query.

That would be a good plan anyway. It's pure luck for you that there is
an implicit int2->text coercion path that allows the text function
lower() to be applied to an int2 field. If your app expects to be able
to apply lower() to any datatype at all, I'd say your app is broken.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stuart 2001-10-14 11:28:31 referencial conlumn contraints and inheritance
Previous Message guard 2001-10-14 04:07:41 to_char()??