Michael Bayer <mike_mp@...> writes:
>> print(query.statement.compile(compile_kwargs={"literal_binds": True}))
>
>note that literal_binds is also used for real SQL, particularly in DDL
>when producing constructs like functional indexes and constraints.
>so the literal values must be compliant towards target backends.
Ah, I didn't realize that. Does that mean that currently sqlalchemy does
not support generating DDL for constraints that include a literal date or
time value?
>>But date and time types, like integers, are small and well-behaved,
Yuck. I had hoped that 'yyyy-mm-dd' would be accepted everywhere but of
course it cannot be that easy. So the literal string will be understood
on some Oracle instances but not others depending on the default date
format? Which means you have to say
to_date('2000-01-01', 'YYYY-MM-DD')
I am using MSSQL and my instance understands ISO8601 dates - but again you
are saying that not all of them will. So it needs
convert(date, '2000-01-01', 102)
or for older MSSQL versions, convert(datetime,...). That will also work
for Sybase.
To be clear, your position is that you will accept a patch adding literal
date serialization for all database backends, but not a patch that only
adds it for some of them (such as the plain string representation used in
the line of code at the top)?
What about if the first version of the patch only handles dates, not
time and datetime types?
>...backend-specific functionality so it doesn’t go in sqltypes.py alone.
Is sqltypes.py the default implementation, and then some backends will
override the methods?
>At the moment it would go as new Date, Time and DateTime types in all
>dialects, but I’d rather avoid having to do that so I think some
>new API on dialect would be needed, such that, Date/Time/DateTime
>literal_processor() call out to a function present on each Dialect
>itself. this would have to degrade gracefully for dialects that don’t
>support the method yet, such as 3rd party dialects.
The alternative would be to provide the default implementation in
sqltypes.py and if a 3rd party dialect hasn't overridden it, it gets the
default representation of 'yyyy-mm-dd'. Might that not be the best way to
degrade gracefully, since most SQL dialects out there in practical use do
at least support this date format?
>the tests for backends are already done, and are in
>lib/sqlalchemy/testing/suite/test_types.py - right
>now SQLite does support literal rendering since SQLAlchemy does it
>anyway. The supporting dialects are
>added to test/requirements.py -> def datetime_literals().
>
>Tests for the “Generic” version would also be added, most likely in
>test/sql/test_types.py.
Thanks. I may start work on a test for the generic version first pending
your decision on the best way to extend it out to the dialects.
--
Ed Avis <
e...@waniasset.com>