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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Ordering problem with varchar (DESC) - from general ml.
Дата
Msg-id 27019.1170261851@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Ordering problem with varchar (DESC) - from general ml.  ("Alexandre Leclerc" <alexandre.leclerc@gmail.com>)
Список pgsql-admin
"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

В списке pgsql-admin по дате отправления:

Предыдущее
От: "Alexandre Leclerc"
Дата:
Сообщение: Ordering problem with varchar (DESC) - from general ml.
Следующее
От: Sidar López Cruz
Дата:
Сообщение: Role privileges