Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
On Fri, Sep 16, 2016 at 10:49 AM, Jinghui Niu wrote: >> If you still want to store it as a string, I guess you'll need to try >> parsing it as a datetime and then fall back to parsing it as a date. > > > Exactly! That's my intention. I'm so excited that my idea has affirmed

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Jinghui Niu
> > If you still want to store it as a string, I guess you'll need to try > parsing it as a datetime and then fall back to parsing it as a date. Exactly! That's my intention. I'm so excited that my idea has affirmed by a pro now:) You haven't said what database you are using SQLite in Python

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
Another option would be to have separate columns for date and time, and leave the time column NULL when it's not present. If you still want to store it as a string, I guess you'll need to try parsing it as a datetime and then fall back to parsing it as a date. You haven't said what database you

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Jinghui Niu
If I store the as DateTime values and with a second column to indicate whether it's a date or datetime, it would look like this for a Date: col1: "2016-09-16 00:00:00", col2: "date only" It looks so messy to me:) I'd prefer to have Date and DateTime distinctively written in my database. I admit

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Jinghui Niu
Thanks for reply. The reason is simple. I plan in the future to accommodate datetime range into that column as well, so storing this logic as plain strings gives the most flexibility. This is a project that I'm learning by making. So I would like to try all the new features for later tasks. I'm

Re: [sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-16 Thread Simon King
Ignore SQLAlchemy for the moment and describe what you are trying to achieve. It looks like you want to store dates and times as strings in your database (rather than the appropriate type), and yet still be able to perform date-related operations on them qhen querying. Is that right? Is there a

[sqlalchemy] SQL expression for function (and/or method) dispatching?

2016-09-15 Thread Jinghui Niu
I have the following code snippet, I marked my question in a comment line inside the hybrid_property.expression part. As you can see, it is now not implemented: from sqlalchemy.ext.declarative import declared_attr from sqlalchemy import Column, Integer, String, Unicode, UnicodeText from