How do I subtract datetimes in SQLite+SQLalchemy? -


i'm using sqlite+sqlalchemy , i'm doing this , sql looks this:

select task.id task_id, task.title task_title task (select sum(coalesce(intervals."end", current_timestamp) - intervals.start) sum_1 intervals task.id = intervals.task_id) > :param_1 

the problem doesn't work because query needs this:

... (select sum(julianday(coalesce(intervals."end", current_timestamp)) - julianday(intervals.start)) sum_1 ... 

but haven't been able find julianday function in sqlalchemy, or how hand-alter query.

how can alter behavior can difference of these values in sqlite?

sqlalchemy has no need define explicitly every function found in every database engine. knows few standard ones, can use sqlalchemy.func.foobar(arg1, arg2, ...) , translated function call foobar(arg1, arg2, ...) in sql. change

@time_spent.expression def time_spent(cls):     return func.coalesce(cls.end, func.current_timestamp()) - cls.start 

to

@time_spent.expression def time_spent(cls):     return func.julianday(func.coalesce(cls.end, func.current_timestamp())) - \            func.julianday(cls.start) 

and should fine. stuck sqlite because julianday not portable, though.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -