you have to rewrite your SQL to support the number of values in the IN clause 
for each parameter set.

On Apr 15, 2010, at 9:54 AM, Chris Withers wrote:

> Hi All,
> 
> I have a big set of queries provided as raw sql like:
> 
> """
> SELECT somestuff FROM somewhere
> WHERE some_date >= :from_date AND some_date <= :to_date
> """
> 
> That's fine, I just blat it at session.execute and provide from_date and 
> to_date in the params dict.
> 
> However, they now wany to supply something like:
> 
> """
> SELECT somestuff FROM somewhere
> WHERE some_date >= :from_date AND some_date <= :to_date
> AND somefield in :values
> """
> 
> Now, I have values as a sequence of strings that I need to provide,
> but supplying in the params dict_ doesn't work:
> 
>  File 
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/orm/session.py",
>  line 753, in execute
>    clause, params or {})
>  File 
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/engine/base.py",
>  line 824, in execute
>    return Connection.executors[c](self, object, multiparams, params)
>  File 
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/engine/base.py",
>  line 874, in _execute_clauseelement
>    return self.__execute_context(context)
>  File 
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/engine/base.py",
>  line 896, in __execute_context
>    self._cursor_execute(context.cursor, context.statement, 
> context.parameters[0], context=context)
>  File 
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/engine/base.py",
>  line 950, in _cursor_execute
>    self._handle_dbapi_exception(e, statement, parameters, cursor, context)
>  File 
> "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.8-py2.5.egg/sqlalchemy/engine/base.py",
>  line 931, in _handle_dbapi_exception
>    raise exc.DBAPIError.instance(statement, parameters, e, 
> connection_invalidated=is_disconnect)
> sqlalchemy.exc.OperationalError: (OperationalError) near "?": syntax error 
> u'AND somefield in ?' [('1', '2', '3')]
> 
> What should I do?
> 
> cheers,
> 
> Chris
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to