- changed status to resolved
Modulus-operator gives ProgrammingError in PostgreSQL (psycopg2).
Issue #624
resolved
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)
-
Account Deleted -
Account Deleted - changed status to open
- removed status
Replying to ants:
Fixed in b191254d8aceca10b40dd5957f3ddf9147a4c534.
Similar problems could be lurking with Oracle, Firebird and SQL Server, can some one run test/sql/query.py OperatorTest on those platforms?
OperatorTest fails on Oracle XE. Patch is in the attached file.
andrija
-
Account Deleted - attached oracle.modulo.patch
Patch for modulo operator on Oracle
-
repo owner - changed status to resolved
thanks for the patch, committed in changeset:2906
though we should look into making more general purpose construct here to avoid the if/then logic.
-
repo owner - removed milestone
Removing milestone: 0.3.9 (automated comment)
- Log in to comment
(original author: ants) Fixed in b191254d8aceca10b40dd5957f3ddf9147a4c534.
Similar problems could be lurking with Oracle, Firebird and SQL Server, can some one run test/sql/query.py OperatorTest on those platforms?