pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.76k stars 297 forks source link

timestamp **with** time zone #326

Closed gduverger closed 4 years ago

gduverger commented 4 years ago

When I insert an aware datetime, Dataset creates a timestamp **without** time zone field for it.

>>> import dataset
>>> import datetime
>>> db = dataset.connect('postgresql://…/test')
>>> now = datetime.datetime.now(datetime.timezone.utc)
>>> db['test'].insert(dict(date=now))
Screen Shot 2020-04-13 at 8 45 06 PM

Is there a way to make that field timestamp **with** time zone, instead? Otherwise, what's the recommended way to handle timezones with Dataset?

therealstein commented 4 years ago

Yes i have a similar problem. I need to set microseconds. In sqlalchemy it would be fsp=6 or something

pudo commented 4 years ago

You can create columns explicitly if you wish to set a very specific type:

from sqlalchemy.types import DateTime

table = db['my_new_table']
table.create_column('date', DateTime(timezone=True))

See also the SQLA type documentation: https://docs.sqlalchemy.org/en/13/core/type_basics.html