views:

236

answers:

1

I don't like how SQLAlchemy treats datetime values with sqlite databases. It stores the values in plain string format. At the same time sqlite recommends using julianday for storing datetime values.

Is there an easy way to change the SQLAlchemy's behaviour here?

PS. Shall I worry about it? May be noone is dealing with julianday just because it's not necessary?

+3  A: 

Actually it is not SQLAlchemy that stores dates as plain strings; SQLite itself does not support date types. It's important that you understand that from the outset; Sqlite does provide some functions for dealing with dates, but those are dates stored as text. That's why SQLAlchemy does some magic in transforming the dates to and from python's datetime type: Per the SQLAlchemy's documentation:

SQLite does not have built-in DATE, TIME, or DATETIME types, and pysqlite does not provide out of the box functionality for translating values between Python datetime objects and a SQLite-supported format. SQLAlchemy’s own DateTime and related types provide date formatting and parsing functionality when SQlite is used. The implementation classes are SLDateTime, SLDate and SLTime. These types represent dates and times as ISO formatted strings, which also nicely support ordering. There’s no reliance on typical “libc” internals for these functions so historical dates are fully supported.

As for using the Julian calendar as opposed to the Gregorian calendar. Are you sure you want that? Might you mean Gregorian dates?

Ken
That's not true. SQLite itself does supports datetypes. They are just implemented in a strange way: http://www.sqlite.org/lang_datefunc.html
Slava Tutushkin
Those really aren't datatypes so much as they're functions that manipulate scalar strings that happen to represent dates.
Ken