Ordering problem with varchar (DESC) - Mailing list pgsql-general

From Alexandre Leclerc
Subject Ordering problem with varchar (DESC)
Date
Msg-id 45C0B9C9.1010609@ipso.ca
Whole thread Raw
Responses Re: Ordering problem with varchar (DESC)  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: Ordering problem with varchar (DESC)  ("Daniel Verite" <daniel@manitou-mail.org>)
Re: Ordering problem with varchar (DESC)  (Erik Jones <erik@myemma.com>)
Re: Ordering problem with varchar (DESC)  ("Brandon Aiken" <BAiken@winemantech.com>)
Re: Ordering problem with varchar (DESC)  ("Daniel Verite" <daniel@manitou-mail.org>)
List pgsql-general
Hi all,

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;
date (date type)  time (varchar)  data
2007-01-17         8h40           d1
2007-01-30         9h30           d2
2007-01-30        12h00           d3
2007-01-30        13h45           d4
2007-01-30        17h20           d5

SELECT * from t1 ORDER BY date, time DESC;
date (date type)  time (varchar)  data
2007-01-30         9h30           d2
2007-01-30        17h20           d5
2007-01-30        13h45           d4
2007-01-30        12h00           d3
2007-01-17         8h40           d1

I don't know why, this is like if the 'time' varchar was trimmed then
used for the ordering.

How can I fix that so that the result is exactly like the first one but
perfectly reversed in it's order?

Best regards.

--
Alexandre Leclerc

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: When an index and a constraint have the same name...
Next
From: "A. Kretschmer"
Date:
Subject: Re: Ordering problem with varchar (DESC)