pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PFC <lists@boutiquenumerique.com>
To: David B <davidb999@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: ORDER BY handling mixed integer and varchar values
Date: Mon, 16 May 2005 21:12:28 +0200
Message-ID: <op.sqvua2ogth1vuj@localhost> (raw)
In-Reply-To: <c76ea21c050516114742818cfa@mail.gmail.com>
References: <c76ea21c050516114742818cfa@mail.gmail.com>

> 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...




view thread (5+ messages)  latest in thread

Message-ID: <op.sqvua2ogth1vuj@localhost>
Permalink:  ../op.sqvua2ogth1vuj@localhost/
Also on:    postgresql.org/message-id/op.sqvua2ogth1vuj@localhost

 · 

reply

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: lists@boutiquenumerique.com, davidb999@gmail.com
  Subject: Re: ORDER BY handling mixed integer and varchar values
  In-Reply-To: <op.sqvua2ogth1vuj@localhost>

* 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