On Thu, 2012-11-08 at 10:04:09 -0500, Michael Bayer wrote:
> yeah, I've shown this recipe as a means to provide cross-platform date
> arithmetic, specifically between Postgresql and SQL Server.  But if
> you are on pure Postgresql, you can just use datetime.timedelta():
> 
> from sqlalchemy import *
> import datetime
> 
> m = MetaData()
> t = Table('event', m, Column('date', DateTime))
> 
> s = t.select().where(t.c.date < func.now() - datetime.timedelta(days=3 * 365))

This is not equivalent to Postgres '3 years'::interval, as timedelta
does not take leap years into account, while interval does.  PostgreSQL
interval behaves similar to dateutil.relativedelta, which has a notion
of months and years.

-- 
Audrius Kažukauskas
http://neutrino.lt/

Attachment: pgpJaZDNTAYVX.pgp
Description: PGP signature

Reply via email to