timezone and postgres

Issue #414 resolved
Former user created an issue

The default setting for sqlalchemy.DateTime columns on postgres databases is on timezone=True, while pythons default setting for datetime stuff seems to be timezone=False, hence the two defaults conflict when comparing a value fetched from postgres with a python datetime.datetime object. This is solvable by using DateTime(timezone=False), however I find it counter-intuitive that these defaults don't harmonize.

This is related to ticket:275

The test programm:

#!/usr/bin/env python2.5

from sqlalchemy import *
from datetime import datetime

global_connect('postgres://myuser:mypass@myhost/mydb')
table = Table('testtable',
    Column('somedate', DateTime()),
    )

table.drop(checkfirst=True)
table.create(checkfirst=True)
table.insert().execute(somedate=datetime.now())
table.select().execute().fetchone().somedate == datetime.now()

Comments (2)

  1. Former user Account Deleted

    Using timezone=False as a default would make this annoyance go away - but does not this impose a backwards incompatiblity (which could be documented)?

  2. Mike Bayer repo owner

    yeah the only solution here would be to change the default. only postgres is even aware of this setting at the moment, and actually its default is "False" within postgres itself as well. so i've no idea why when i implemented #275 i made the default True - ive switched it to be False for both DateTime and Time types in changeset:2184.

    as far as docs, it'll be in the changelog and the generated documentation....id imagine most PG users are setting the flag explicitly right now.

  3. Log in to comment