I need to write some queries using bitwise logic AND/OR, but only when I use oracle database, I receive the following error:
sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) ORA-01036: illegal variable name/number [SQL: 'SELECT "Cars"."Id", "Cars"."Name", "Cars"."Price" \nFROM "Cars" \nWHERE ("Cars"."Price" & :Price_1) > :param_1'] [parameters: {'Price_1': 32768, 'param_1': 0}]
if I use PostgreSql or Sqlite, I receive the expected answer.
create_engine('sqlite:///cars.sqlite3') OK! create_engine('postgresql+psycopg2://xxx:yyy@localhost:5432/db_sql_alchemy') OK! create_engine('oracle+cx_oracle://xxx:yyy@localhost:49161/xe') ERROR!
Other operations such as select, where clauses, table creation, are working as expected in all 3 databases.
Watching the error log, it seems that the query its not being translated correctly to oracle syntax. I was expecting something like this:
SELECT "Cars"."Id", "Cars"."Name", "Cars"."Price" FROM "Cars" WHERE (BitAnd("Cars"."Price", 32768) > 0);
The operation that generates the error is:
stm = stm.where(cars.c.Price.op('&')(0x8000) > 0)
I am using Python 2.7.12 and SQLAlchemy==1.1.2.
&operator. Try theBITANDfunction instead. - univerioop()generics render as is. No translation involved (iirc). You got what you requested. - Ilja Everilä.ColumnOperators.op- there is no compilation for the specific databse? in the docs, the operator +, is compiled according the DB choice In which cases do we have compilation for the speficic engine? Could you give more detais, code samples, patters, on how to "custom construct and customize the compilation accordingly" - user3632887