How To Override NULL Value From Aggregate Query Using MySQLdb Module In Python?
I am selecting the maximum date value from a MySQL database table in python using the MySQLdb module. If the result comes back as null, I want to override it with a default value.
Solution 1:
I could do this in the MySQL using a sub-query, but would prefer to do it in python.
Why do you say you need a subquery? You can just use COALESCE:
"select COALESCE(max(date_val), 'your_default_value_here') from my_table;"
Solution 2:
Try this:
min_date = cur.fetchone()[0]
min_date = min_date if min_date is not None else default_value
Post a Comment for "How To Override NULL Value From Aggregate Query Using MySQLdb Module In Python?"