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. I could do this in the MySQL using a sub-query, but would prefer to do it in python.
Any recommendations on a simple way to do this? I figure this is an easy one, but I'm new to python so I thought it was worth asking.
Here's my code so far:
db=MySQLdb.connect(...)
cur = db.cursor()
cur.execute("select max(date_val) from my_table;")
min_date = cur.fetchone()[0]
Thanks in advance!
Edit: "print min_date" outputs "None" if the value is null. I want to override it with a default value, such as "2010-01-01".