SA, and rightly so, thinks a date is a date.

So, two approaches:

If you want to "guess" at the dates, keep the input partial dates as
strings. Use the excellent dateutil package to parse the "fuzzy" strings
into datetime objects and store those.

If you want to store the fuzzy dates themselves, just use a string column
type and store the data there, parse it when you need it.

Most databases are pretty strict about dates, so you won't have much luck
trying to store partial dates, except with perhaps Sqlite (which stores
dates as strings anyway) or MySQL, which has so many quirks and problems
with date handling that they can barely be called date types. Get ready for
a bunch of jokes about MySQL and dates.....

Rick


On 3/4/07, Mel Collins <[EMAIL PROTECTED]> wrote:
>
>
> Hey all,
> I have an application which needs to support 'incomplete' dates -
> those where the month or day are unknown (or even the year, why not?).
> MySQL supports doing this in it's Date column type (I don't know
> about other DBs), so for example I can have a date field containing:
> "1998-10-00".
> Unfortunately, python/SA always attempts to read date columns into
> the datetime.date type, which doesn't support incomplete dates, and
> you end up with None.
> I've tried overriding the column definition (I use reflection) in the
> SA table declaration, to make it a String, but it is still read from
> the database into a datetime.date object (which SA then tries to
> decode() unsuccessfully). I guess this means that it's outside of SA
> that the column is made a datetime.date?
>
> As I haven't yet found any other way around this, my only recourse
> seems to be to split the date columns into three, which just feels
> wrong to me. Can anyone suggest a more elegant solution?
>
> Takk,
> - Mel C
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to