ORDER BY results

Поиск
Список
Период
Сортировка
От Howard Cole
Тема ORDER BY results
Дата
Msg-id 4332AF44.7060802@selestial.com
обсуждение исходный текст
Ответы Re: ORDER BY results  (Michael Fuhr <mike@fuhr.org>)
Re: ORDER BY results  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hi,

I have a query which presents results sorted using the SQL  "ORDER BY...
LIMIT". Now my question is...  if the column that the order refers to
has some repeated data, will the order of results always be the same?

For instance, say I have a table as follows:

create table example {id serial primary key, stuff int};

Now suppose I the table is populated as follows:

ID                STUFF
1                  10
2                  11
3                  11
4                  12

Now if i try SELECT ID,STUFF FROM EXAMPLE ORDER BY STUFF; I might expect

ID                STUFF
1                  10
2                  11
3                  11
4                  12

but possibly could get

ID                STUFF
1                  10
3                  11
2                  11
4                  12

... Depending on the implementation. Whichever result I get, can I
always expect the output in the same way? Or should I ensure this by
sorting by the ID aswell

e.g. SELECT ID,STUFF FROM EXAMPLE ORDER BY STUFF, ID; - which would
always give the same order.

In case you are interested, the application for this problem is the
presentation of partial results using LIMIT (as per search results
20,21...30) - for instance could the following present different results
to the same client...

SELECT ID,STUFF FROM EXAMPLE WHERE STUFF=11 ORDER BY STUFF LIMIT 0, 1;

Could give the following on one transaction
2                  11
And the following on another transaction
3                  11

I am not bothered about which way the results are presented and I am
aware that the order would be implementaion specific, but obviously the
results presented should always be the same for my app.

Regards,

Howard Cole
www.selestial.com



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

Предыдущее
От: Gábor Farkas
Дата:
Сообщение: Re: Slow search.. quite clueless
Следующее
От: Jan Wieck
Дата:
Сообщение: Re: Cost based SELECT/UPDATE