Ah, makes sense. Thanks.
On Dec 11, 5:50 pm, Michael Bayer <[email protected]> wrote: > you're compiling the text() construct against the DefaultDialect, when > it needs to be compiled against the PG dialect in order for the :num > bind param to be converted to PG's desired format, %(num)s. Also im > not 100% sure if PG allows bind params for LIMIT, probably does though. > > On Dec 11, 2008, at 5:33 AM, zepolen wrote: > > > > > > > It seems compile()'ing a query results in the default bindparams not > > being used, is this a bug? > > > Simple test case: > > >>>> from sqlalchemy import * > >>>> engine = create_engine('postgres://uname:pw...@localhost/testdb') > >>>> query = text('select * from table limit :num', > >>>> bindparams=[bindparam('num', value=50)]) > >>>> engine.execute(query).rowcount > > 50 > >>>> query = text('select * from table limit :num', > >>>> bindparams=[bindparam('num', value=50)]).compile() > >>>> query.params > > {'num': 50} > >>>> engine.execute(query).rowcount > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > File "/home/zepolen/projects/test/ENV/lib/python2.5/site-packages/ > > SQLAlchemy-0.5.0rc4-py2.5.egg/sqlalchemy/engine/base.py", line 1174, > > in execute > > return connection.execute(statement, *multiparams, **params) > > File "/home/zepolen/projects/test/ENV/lib/python2.5/site-packages/ > > SQLAlchemy-0.5.0rc4-py2.5.egg/sqlalchemy/engine/base.py", line 806, in > > execute > > return Connection.executors[c](self, object, multiparams, params) > > File "/home/zepolen/projects/test/ENV/lib/python2.5/site-packages/ > > SQLAlchemy-0.5.0rc4-py2.5.egg/sqlalchemy/engine/base.py", line 865, in > > _execute_compiled > > return self.__execute_context(context) > > File "/home/zepolen/projects/test/ENV/lib/python2.5/site-packages/ > > SQLAlchemy-0.5.0rc4-py2.5.egg/sqlalchemy/engine/base.py", line 878, in > > __execute_context > > self._cursor_execute(context.cursor, context.statement, > > context.parameters[0], context=context) > > File "/home/zepolen/projects/test/ENV/lib/python2.5/site-packages/ > > SQLAlchemy-0.5.0rc4-py2.5.egg/sqlalchemy/engine/base.py", line 927, in > > _cursor_execute > > self._handle_dbapi_exception(e, statement, parameters, cursor) > > File "/home/zepolen/projects/test/ENV/lib/python2.5/site-packages/ > > SQLAlchemy-0.5.0rc4-py2.5.egg/sqlalchemy/engine/base.py", line 909, in > > _handle_dbapi_exception > > raise exc.DBAPIError.instance(statement, parameters, e, > > connection_invalidated=is_disconnect) > > sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or > > near ":" > > LINE 1: select * from table limit :num > > ^ > > 'select * from table limit :num' {'num': 50} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
