pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexandre Leclerc <alexandre.leclerc@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Ordering problem with varchar (DESC) - from general ml.
Date: Wed, 31 Jan 2007 11:44:11 -0500
Message-ID: <27019.1170261851@sss.pgh.pa.us> (raw)
In-Reply-To: <1dc7f0e30701310832r2da685d4ifd858f34373af84a@mail.gmail.com>
References: <1dc7f0e30701310832r2da685d4ifd858f34373af84a@mail.gmail.com>

"Alexandre Leclerc" <alexandre.leclerc@gmail.com> writes:
> We have a column (varchar) that has plain text time and it is indexed.
> When I do a query with the index, all the data is in the right order,
> but when I user ORDER BY .. DESC, the order is messed up. Example:

> By index 1: (date, time, data)
> SELECT * from t1;

What makes you think that query is using an index?  It's probably just
returning the data in physical order, which might look correctly ordered
if you inserted all the data in time order to start with.

> SELECT * from t1 ORDER BY date, time DESC;

Perhaps you mean "ORDER BY date DESC, time DESC" ?

I don't actually see how a varchar field set up like that would sort
in a sensible numeric order at all --- text comparisons are unlikely
to do what you'd like with the optional leading one.  Consider replacing
the varchar with a field of type TIME.

			regards, tom lane



view thread (2+ messages)

Message-ID: <27019.1170261851@sss.pgh.pa.us>
Permalink:  ../27019.1170261851@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27019.1170261851@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, alexandre.leclerc@gmail.com
  Subject: Re: Ordering problem with varchar (DESC) - from general ml.
  In-Reply-To: <27019.1170261851@sss.pgh.pa.us>
  References: <1dc7f0e30701310832r2da685d4ifd858f34373af84a@mail.gmail.com> <27019.1170261851@sss.pgh.pa.us>

* 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