On Fri, Sep 16, 2016 at 10:49 AM, Jinghui Niu <niujing...@gmail.com> 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 by a
> pro now:)

I'm definitely not a pro, but I'm also not affirming your idea... ;-)

>> You haven't said what database you are using
> SQLite in Python 3.
> But I'm still more inclined towards storing a long string of datetime/date
> into a column, plus a suffix column indicating whether it's a date, a
> datetime, or in future a time range. Is there a way to do this at SQL
> expression level using hybrid_property?
> I'm definitely going to check out TypeDecorator. It's another new thing but
> sounds very interesting. Thanks for mentioning!

The entire purpose of hybrid properties is to be able to perform
useful operations during queries, eg:

session.query(SomeObj).filter(SomeObj.timepoint > '2016-01-01')

For this to work, I would imagine that the SQL construct that
"SomeObj.timepoint" resolves to would have to have a consistent type.
I know sqlite is relaxed about data types, so mixing dates and
datetimes is probably fine, but I don't see how you could meaningfully
query a column which contains a mix of datetimes and durations.

If you're not going to use the property when querying, and you
potentially need to aggregate multiple columns, I would have thought
that what you really need is a plain python property, which does the
string->value conversion in the getter and the opposite in the setter.


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+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to