Google+ Followers

zondag 24 mei 2015

Why I like PostgreSQL more than MySQL: NULLS LAST

Sometimes you want to sort values in c olumn that contains NULL values, and the NULL's appear at the wrong end of your list.
For example; sorting by date descending will put the null values first and then the dates starting at the newest date.

In MySQL you can "solve" this by ordering by the inverse of the value: ORDER BY -datefield, which means it can't use a index.

In PostgreSQL you can just ask for what you want: ORDER BY datefield NULLS LAST

Just one of many seemingly insicgnificant features that make life with your database so much simpler....