Default orderBy research 2/17/2011

From CDOT Wiki
Revision as of 12:15, 26 March 2011 by Peter.liu (talk | contribs)
Jump to: navigation, search

While debugging some unit tests (testRead, testUpdate) I have noticed that the error message is the following:"Doesn't match the serialized representation".
I checked the data and in xml file and the one I get when running the composed query in PostgreSQL. They are identical.
I ran the same tests in MySQL: I've got the same data as in PostgreSQL. The only difference is the order of rows, so I figured it has something to do with default ordering in PostgreSQL:

The null value sorts higher than any other value. In other words, with ascending sort order, null values 
sort at the end, and with descending sort order, null values sort at the beginning.
If not specified, ASC is assumed by default.

And in the MySQL:

When doing an ORDER BY, NULL values are presented first if you do ORDER BY ... ASC (default) and last if you do ORDER BY ... DESC.        

This explains why testUpdates gives the specified message, and I guess we have the same issue when we are trying to read without order by clause.


Solution: Every time we have ORDER BY we specify nulls first (this option is supported in PostgreSQL 8.3 and later).