I would like to sort records on a field such that NULL values get
sorted to the end. In MySQL the suggested solution is to use ISNULL.
For example
SELECT name FROM person ORDER BY ISNULL(name), name;
I tried other approaches such as sorting the rows returned from a
select but they were not practical as all records need to be retrieved
and in the application I am working on I only want a subset (ie. I am
using limitby)
I was able to implement this in web2py with the following patch.
gluon/dal.py
class BaseAdapter(ConnectionPool):
def ISNULL(self,first):
return 'ISNULL(%s)' % self.expand(first)
class Expression(object):
def isnull(self):
return Expression(self.db, self.db._adapter.ISNULL, self,
None, self.type)
Is there any desire for this feature in the trunk? I haven't given any
consideration to databases other than MySQL. I would be willing to dig
into this further if there is interest.