Databases don't order rows unless you tell them so

Updated . Posted . Visible to the public. Repeats.

There is no such thing as a "default order" of rows in database tables.

For instance, when you paginate a result set: When using LIMIT, it is important to use an ORDER BY clause that constrains the result rows into a unique order. Otherwise you will get an unpredictable subset of the query's rows. You might be asking for the tenth through twentieth rows, but tenth through twentieth in what ordering? The ordering is unknown, unless you specified ORDER BY.

In Rails, if you use Record.first or Record.last, it will default to ordering by id.

See also

Last edit
Michael Leimstädtner
Keywords
postgresql
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2015-05-31 18:28)