Modulus-operator gives ProgrammingError in PostgreSQL (psycopg2).

Issue #624 resolved
Former user created an issue

Using the modulus operator with PostgreSQL and the latest version of psycopg2, a ProgrammingError-exception is raised. While this works with SQLite, psycopg2 seems to want an escaped %-operator:

>>> from sqlalchemy import *
>>> def testmod(db):
...     try:
...         print db.scalar(select([% literal(2)](literal(1))))
...     except Exception, e:
...         print e
...     try:
...         print db.scalar(select([literal(1).op('%%')(literal(2))](literal(1).op('%%')(literal(2)))))
...     except Exception, e:
...         print e
... 
>>> testmod(create_engine('sqlite://'))
1
(OperationalError) near "%": syntax error u'SELECT ? %% ?' [2](1,)
>>> testmod(create_engine('postgres://foo@bar/baz'))
(ProgrammingError) argument formats can't be mixed 'SELECT %(literal)s % %(literal_1)s' {'literal_1': 2, 'literal': 1}
1

Comments (5)

  1. Log in to comment