Ben Johnson wrote: > I just switched to Postgres and some of my tests are failing. It seems > that Postgres defaults by ordering data by ID DESC, whereas MySQL > defaults to ordering by ID ASC.
As Jeremy correctly pointed out, without an ORDER clause, your records may be returned in any order. [...] > > In various places throughout my application I am doing things like: > > User.first > > This obviously is not good with the order of the data is not consistent. > I also feel like the first User should return the first user, not the > last one created. There is no guarantee of that -- without the ORDER clause, the database is free to return the first user created, the last user created, or one somewhere in the middle. User.first just returns whichever user the DB decided to retrieve first. If you need a specific ordering, you need an order clause. > > What do you think? I think you don't quite understand how SQL databases retrieve records. Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

