I have an SQLite database in which I have declared certain columns type DATE (allowable but, of course, ignored by SQLite as it does not have a DATE type). I am storing my dates as SQLite date strings.
When connecting from Python, I pass detect_types=sqlite3.PARSE_DECLTYPES
to the connection. This allows the sqlite library to correctly determine which columns contain dates and it correctly provides me with a date
object, not a string when I read from these columns.
However, if I aggregate a date column, I get back a string, not a date:
SELECT MIN(ReportDate) FROM PatientReports WHERE PatientID = ?;
produces a string, not a date value. Interestingly this SQL:
SELECT ReportDate FROM PatientReports WHERE PatientID = ? ORDER BY ReportDate DESC LIMIT 1;
correctly produces a date value (and this is the work-around I am using).
Question: Is there some way I can modify either the first SQL statement or my database definition to allow Python to preserve the implied date conversion?