On Mon, Mar 2, 2020, at 10:07 AM, Balukrishnan wrote:
> Hi friends,
> 
> I am using some expressions in the select values itself like this.
> 
>> data = select([testb.c.var1.op('&')(5)]).From(testb).execute()
> 
> But the corresponding SQL generated is
> 
>> SELECT (testb.var1 & $1) != $2 AS anon_1 FROM testb, Args: (1, 0)
> 
> I can't label the column-like testb.c.var1.op('&')(5).label('Var'). Why this 
> happening and how can I label that column with a valid name. Please help.
> 
> also tried (but getting error),
>  * data = select([testb.c.var1.op('&')(5).label('VAR')]).From(testb).execute()

the first example is correct, and assuming you use the correct method for the 
froms "select_from", no error is generated:

from sqlalchemy import select, table, column


testb = table('testb', column('var1'))

stmt = select([testb.c.var1.op('&')(5).label('VAR')]).select_from(testb)

print(stmt)


SELECT testb.var1 & :var1_1 AS "VAR" 
FROM testb





>  * data = select([testb.c.var1.label('VAR').op('&')(5)]).From(testb).execute()
>  * data = select([testb.c.var1.alias('VAR').op('&')(5)]).From(testb).execute()
>  * data = select([testb.c.var1.op('&')(5).alias('VAR')]).From(testb).execute()
> 

> --
>  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 [email protected].
>  To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/c9e4becd-e72f-4797-aea7-b0bac759ccf2%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/c9e4becd-e72f-4797-aea7-b0bac759ccf2%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/71c46ae8-9d3d-4036-97a9-ccc8c0ce249d%40www.fastmail.com.

Reply via email to