Re: ORDER BY handling mixed integer and varchar values

From: PFC <lists(at)boutiquenumerique(dot)com>
To: "David B" <davidb999(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER BY handling mixed integer and varchar values
Date: 2005-05-16 19:12:28
Message-ID: op.sqvua2ogth1vuj@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Is there any elegent query you folks can think of that combines the
> two so I can one query that has alpha sorting on alpha categories and
> numeric sorting on numeric values that are in the same column??

solution 1 (fast)

make a separate column which contains the integer value (updated via a
trigger) or NULL if it's a textual value, then sort on it

solution 2

order by the string padded to a fixed length by adding spaces to the left :
(here an underscore is a space):

____1
___10
_ABCD

I think there's a LPAD function (look in the docs) to do that... you can
use only the first N (like 10) chars of the string...

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Edmund Bacon 2005-05-16 19:18:22 Re: ORDER BY handling mixed integer and varchar values
Previous Message David B 2005-05-16 18:47:59 ORDER BY handling mixed integer and varchar values