I am using SQLAlchemy and am having an issue wrt to an SQLite error:
SQLite Date type only accepts Python date objects as input.
[SQL: 'SELECT anon_1.patient_sid AS sid FROM
(SELECT clinical_data.patient_sid AS patient_sid FROM clinical_data
WHERE clinical_data.event_date >= ?) AS anon_1']
I understand perfectly the meaning of the error, but I do not understand
why it is happening in my case.
The parameter that I am passing to do the date comparison in the query
above
clinical_data.event_date >= ?
is set as:
valdate = datetime.strptime('1776-01-01 00:00:00', "%Y-%m-%d %H:%M:%S").date
()
and, I have validated that the data type of `valdate` is `<type
'datetime.date'>`
The class used to construct the query is:
class ClinicalData(db.Model):
__tablename__ = 'clinical_data'
id = Column(Integer, primary_key=True, autoincrement=True)
patient_id = Column(Integer)
patient_sid = Column(Integer)
string_value = Column(String(255))
double_value = Column(Float)
data_type_id = Column(Integer)
event_date = Column(Date)
ontology_id = Column(Integer)
attribute_id = Column(Integer)
project_id = Column(Integer)
replaced_by_id = Column(Integer)
date_record_added = Column(DateTime)
parent = Column(Integer)
num_children = Column(Integer)
lft = Column(Integer)
rgt = Column(Integer)
The SQLAlchemy documentation for SQLite states (see [SQLAlchemy SQLite
documentation][1]
<http://docs.sqlalchemy.org/en/latest/dialects/sqlite.html>) that
"SQLAlchemy’s own DateTime and related types provide date formatting and
parsing functionality when SQlite is used..."
Note that when I use `DateTime` as a data type in my class model on the
`event_date` attribute I get the following error
SQLite DateTime type only accepts Python datetime and date objects as input.
For this I define
valdate = datetime.strptime('1776-01-01 00:00:00', "%Y-%m-%d %H:%M:%S")
without the `date()` method. As expected, `type(valdate)` in this case
yields
<type 'datetime.datetime'>
I have tried every combination of creating the variable `valdate` with the
`event_date` attribute of my class.
I am not asking how to convert my string object to a python datetime
object, nor am I asking what the error means. I am not sure exactly why I
keep getting this error when everything appears to be sufficiently defined.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.