Thank you sir, it's working.

On Tuesday, February 25, 2020 at 10:52:21 PM UTC+5:30, Simon King wrote:
>
> SQLAlchemy overrides the & operator: 
>
>     
> https://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.and_
>  
>
> You can use the "op" function to get at the postgres & operator: 
>
>     
> https://docs.sqlalchemy.org/en/13/core/sqlelement.html#sqlalchemy.sql.expression.ColumnElement.op
>  
>
> Something like this: 
>
>     select([testa.c.id.op("&")(15)]) 
>
> Hope that helps, 
>
> Simon 
>
> On Tue, Feb 25, 2020 at 5:02 PM Balukrishnan <balu...@gmail.com 
> <javascript:>> wrote: 
> > 
> > Table definition 
> > 
> > from sqlalchemy import * 
> > testa = Table( 
> >     "testa", 
> >     metadata, 
> >     Column("id", BigInteger, primary_key=True), 
> >     Column("str_var_a", String, nullable=True), 
> >     Colmn("bool_var_a", Boolean, nullable=True), 
> > ) 
> > 
> > and I need to execute a query like. 
> > 
> > select([testa.c.id & 15]) 
> > 
> > But while executing this query getting an error 
> > 
> > Traceback (most recent call last): 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/operators.py",
>  
> line 81, in __and__ 
> >     return self.operate(and_, other) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 731, in operate 
> >     return op(self.comparator, *other, **kwargs) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/operators.py",
>  
> line 81, in __and__ 
> >     return self.operate(and_, other) 
> >   File "<string>", line 1, in <lambda> 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/type_api.py",
>  
> line 67, in operate 
> >     return o[0](self.expr, op, *(other + o[1:]), **kwargs) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/default_comparator.py",
>  
> line 147, in _conjunction_operate 
> >     return and_(expr, other) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 2098, in and_ 
> >     return cls._construct(operators.and_, True_, False_, *clauses) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 2028, in _construct 
> >     clauses = [ 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 2029, in <listcomp> 
> >     _expression_literal_as_text(clause) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 4569, in _expression_literal_as_text 
> >     return _literal_as_text(element) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 4592, in _literal_as_text 
> >     return _literal_as(element, _no_text_coercion) 
> >   File 
> "/Users/users_name/Projects/x_men/lib/python3.8/site-packages/sqlalchemy/sql/elements.py",
>  
> line 4582, in _literal_as 
> >     raise exc.ArgumentError( 
> > sqlalchemy.exc.ArgumentError: SQL expression object expected, got object 
> of type <class 'int'> instead 
> > 
> > But in Postgres using psql command I can perform the query SELECT id & 
> 15 FROM testa;. Is there any support for this in sqlalchemy. 
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description. 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to sqlal...@googlegroups.com <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/37691a3d-826a-4311-bbdb-6ba3eb67b95a%40googlegroups.com.
>  
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/6c5f2781-d1ca-45b1-b847-41c44377b3b8%40googlegroups.com.

Reply via email to