Re: [sqlalchemy] Querying mssql time columns
Thanks Michael, you're correct I'm using pyodbc with FreeTDS, which doesn't recognize the time datatype (and it seems FreeTDS doesn't support anything above SQLServer 2005). And you're right, this is not a SQLAlchemy issue. Sorry about that. I guess I can work around this by using time.isoformat() in filter constraints. Hope that's portable to windows! Thanks (again) for your help--this is the second time you've helped me out here. Much appreciated. Simon. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/pyeq1WoO18IJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] Querying mssql time columns
On Oct 31, 2011, at 1:18 AM, Simon Haines wrote: > I think I've found a bug--can anyone else confirm this? It appears that > SQLAlchemy cannot query SQLServer time columns because Python datetime.time > objects are always promoted to full datetime types. Once promoted the > SQLServer returns the error: 'The data types time and datetime are > incompatible in the greater than operator. (402) (SQLExecDirectW)'. > > The type promotion occurs in sqlalchemy/dialects/mssql/base.py:268-276. What DBAPI are you using ? The date/time behavior there is all tailored to suit what the DBAPIs want. Also some comparisons aren't possible with SQL server, it has extremely limited date functionality. Basically SQLAlchemy can only do what the DBAPI allows. As the comments there indicate, Pyodbc crashes if a datetime.time() is passed directly, this might be considered a Pyodbc bug if that behavior can be re-confirmed ,as this code is a few years old. Assuming you're using pyodbc, you'd need to get your query to work as follows first: import pyodbc import datetime conn = pyodbc.connect("dsn=ms_2005;UID=scott;PWD=tiger") cursor = conn.cursor() # example: cursor.execute("SELECT ?", datetime.time(12, 15, 0)) print cursor.fetchall() # put your statement here using ? for bound parameters cursor.execute("", ) print cursor.fetchall() show me a working query with the DBAPI (again assuming pyodbc here) and I will adjust any incompatibilities on the SQLAlchemy side. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Querying mssql time columns
I think I've found a bug--can anyone else confirm this? It appears that SQLAlchemy cannot query SQLServer time columns because Python datetime.time objects are always promoted to full datetime types. Once promoted the SQLServer returns the error: 'The data types time and datetime are incompatible in the greater than operator. (402) (SQLExecDirectW)'. The type promotion occurs in sqlalchemy/dialects/mssql/base.py:268-276. Interestingly, according to the documentation in this file, SQLAlchemy can already determine whether the DATE and TIME types are supported (in SQLServer 2008 or later), and I have confirmed it emits the correct DDL but still treats all bound time values as DATETIMEs anyway. Is this a bug or am I missing something? Many thanks, Simon. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/_30ui_LT8qcJ. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.