From: Ragnar Hafstað <gnari@simnet.is>
To: David B <davidb999@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER BY handling mixed integer and varchar values
Date: Mon, 16 May 2005 19:32:40 +0000
Message-ID: <1116271960.8157.4.camel@localhost.localdomain> (raw)
In-Reply-To: <c76ea21c050516114742818cfa@mail.gmail.com>
References: <c76ea21c050516114742818cfa@mail.gmail.com>
On Mon, 2005-05-16 at 11:47 -0700, David B wrote:
(sorting text columns numerically)
> And of course I get stuff ordered as I want it.
> BUT… with many product categories being numeric based they come out in
> wrong order '10 comes before 2" etc.
>
> So I tried
> Select product_desc, product_price, product_cat
> Order by cast(product_cat as integer), product_price
>
> And that worked for the numberic based categories.
>
> I don't know of a query will be across alpha or numeric categories.
> 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??
select product_desc, product_price, product_cat
order by cast(product_cat as integer), product_cat, product_price
gnari
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gnari@simnet.is, davidb999@gmail.com
Subject: Re: ORDER BY handling mixed integer and varchar values
In-Reply-To: <1116271960.8157.4.camel@localhost.localdomain>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox