X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 28EB0528EF for ; Mon, 16 May 2005 16:32:39 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 25949-01 for ; Mon, 16 May 2005 19:32:34 +0000 (GMT) Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) by svr1.postgresql.org (Postfix) with ESMTP id A8C0B528E7 for ; Mon, 16 May 2005 16:32:32 -0300 (ADT) Received: from gnari ([85.220.28.44] [85.220.28.44]) by quasar.skima.is with ESMTP; Mon, 16 May 2005 19:32:32 Z Subject: Re: ORDER BY handling mixed integer and varchar values From: Ragnar =?ISO-8859-1?Q?Hafsta=F0?= To: David B Cc: pgsql-sql@postgresql.org In-Reply-To: References: Content-Type: text/plain; charset=windows-1251 Date: Mon, 16 May 2005 19:32:40 +0000 Message-Id: <1116271960.8157.4.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/115 X-Sequence-Number: 21428 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