Sorting, when values are equal....

Started by Net Virtual Mailing Listsover 21 years ago3 messagesgeneral
Jump to latest
#1Net Virtual Mailing Lists
mailinglists@net-virtual.com

Hello,

If I do something like:

SELECT * FROM sometable ORDER BY somerow DESC LIMIT 1 OFFSET 2;

.. and there are multiple rows in sometable where somerow is identical,
am I assured that the values will always come back in the same order?
..... Or do I need to ensure that a second sort (such as the oid?) is used?

Thanks!

- Greg

#2Martijn van Oosterhout
kleptog@svana.org
In reply to: Net Virtual Mailing Lists (#1)
Re: Sorting, when values are equal....

On Mon, Oct 25, 2004 at 04:45:15AM -0700, Net Virtual Mailing Lists wrote:

Hello,

If I do something like:

SELECT * FROM sometable ORDER BY somerow DESC LIMIT 1 OFFSET 2;

.. and there are multiple rows in sometable where somerow is identical,
am I assured that the values will always come back in the same order?
..... Or do I need to ensure that a second sort (such as the oid?) is used?

No order in guarenteed or implied unless you specify it. So you'll need
another field to order by, generally the primary key works well..
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Net Virtual Mailing Lists (#1)
Re: Sorting, when values are equal....

Net Virtual Mailing Lists wrote:

If I do something like:

SELECT * FROM sometable ORDER BY somerow DESC LIMIT 1 OFFSET 2;

.. and there are multiple rows in sometable where somerow is
identical, am I assured that the values will always come back in the
same order? .....

No.

Or do I need to ensure that a second sort (such as
the oid?) is used?

Yes.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/