hi all,
I've been trying to work out some SQLalchemy code to query two datetime
columns and choose the one closest in time. I have some code that does this,
but it requires using PostgreSQL and looks a little messy:
query = query.order_by(ABS(EXTRACT(EPOCH FROM (header.utdatetime -
you can emit that exact SQL using func.abs() in conjunction with the extract()
function, which is a standalone SQLA construct.
from sqlalchemy import func, extract
func.abs(extract('epoch', header.udatetime - self.header.udatetime))
On Jan 27, 2011, at 4:21 PM, Petra Clementson wrote:
hi
haha you guys make it so easy for us and yet we still can't get. Thanks so
much for your help! I think that'll do me just fine.
On Thu, Jan 27, 2011 at 3:57 PM, Michael Bayer mike...@zzzcomputing.comwrote:
you can emit that exact SQL using func.abs() in conjunction with the
extract()