sqlite problem with datetime format YYYY-MM-DDTHH:mm:ss

3,192 views
Skip to first unread message

Massi

unread,
Sep 3, 2015, 8:05:50 AM9/3/15
to sqlalchemy
Hi everyone,

I'm trying to use sqlalchemy (0.9.10) to read a sqlite table which contains some datetime columns. As the title says these column are given in the format YYYY-MM-DDTHH:mm:ss (I did not create the table). When I execute the query, it succeeds, but when I try to convert the rows to lists I get the following error:

ValueError: Couldn't parse datetime string: u'1957-09-04T23:04:37'

If I try to create a similar table via sqlalchemy and then to read the data everything works fine. The data in this case is stored in the format YYYY-MM-DD HH:mm:ss.
Any hint?

Thanks in advance!

Simon King

unread,
Sep 3, 2015, 9:54:45 AM9/3/15
to sqlal...@googlegroups.com
You could try passing the regexp parameter to the DateTime column in
your table definition:

http://docs.sqlalchemy.org/en/rel_1_0/dialects/sqlite.html#sqlalchemy.dialects.sqlite.DATETIME

Hope that helps,

Simon

Massi

unread,
Sep 3, 2015, 10:54:52 AM9/3/15
to sqlalchemy
Hi Simone,

thank you for your reply. Unfortunately I don't create the table so I don't define the table, I only load it from the DB. I hope I intended your suggestion correctly.

Thanks again.

Simon King

unread,
Sep 3, 2015, 11:18:29 AM9/3/15
to sqlal...@googlegroups.com
That's fine - the "regexp" argument is only used when interpreting the
data that comes back from sqlite - it doesn't depend on you actually
creating the table from SQLAlchemy.

It does require that you have an in-python "definition" of the table
structure, which I assume you already have, unless you are simply
using SQLAlchemy to issue raw SQL to sqlite. Do you have any table
definitions in your Python code, or are you using reflection?

If you are using reflection, you can override specific column
definitions as described at

http://docs.sqlalchemy.org/en/rel_1_0/core/reflection.html#overriding-reflected-columns

and

http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/declarative/table_config.html#using-reflection-with-declarative

Simon
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+...@googlegroups.com.
> To post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

Massi

unread,
Sep 3, 2015, 11:29:46 AM9/3/15
to sqlalchemy
Thanks a lot!!
Reply all
Reply to author
Forward
0 new messages