Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

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



"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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group