Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following database structure using SQLAlchemy using Postgresql with Flask:

class Attendance(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  time = db.Column(db.DateTime(timezone=True))

When I get a date from the user and try and query it against the date of the models:

from_date = time.strptime(request.args['from_attendance'],'%m/%d/%Y')
to_date = time.strptime(request.args['to_attendance'],'%m/%d/%Y')
dates = Attendance.query.filter(Attendance.time < from_date,Attendance.time > to_date).all()

I get the following error:

sqlalchemy.exc.ProgrammingError
ProgrammingError: (ProgrammingError) can't adapt type 'time.struct_time' 'SELECT attendance.id     AS attendance_id, attendance.time AS attendance_time, attendance.status AS attendance_status,........

I believe this is a postgresql specific issue, but I am really at a loss for words.

share|improve this question
    
What happens if you pass the dates as strings in the from YYYY-MM-DD as string rather than a struct_time? –  Joe Doherty Mar 11 at 17:47

1 Answer 1

up vote 1 down vote accepted

Datetime columns in Flask-SQLAlchemy are datetime objects. You're using time module to parse.

Try:

from_date = datetime.datetime.strptime(request.args['from_attendance'],'%m/%d/%Y')
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.