Re: Ordering problem with varchar (DESC) - from general ml.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Alexandre Leclerc" <alexandre(dot)leclerc(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Ordering problem with varchar (DESC) - from general ml.
Date: 2007-01-31 16:44:11
Message-ID: 27019.1170261851@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"Alexandre Leclerc" <alexandre(dot)leclerc(at)gmail(dot)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

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Andrew Zahn 2007-01-31 16:56:21 postmaster udp ports?
Previous Message Alexandre Leclerc 2007-01-31 16:32:09 Ordering problem with varchar (DESC) - from general ml.