anon_label issue. Need to label with a valid name in the select query

15 views
Skip to first unread message

Balukrishnan

unread,
Mar 2, 2020, 10:07:00 AM3/2/20
to sqlalchemy
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()
  • 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()

Mike Bayer

unread,
Mar 2, 2020, 11:24:35 AM3/2/20
to noreply-spamdigest via sqlalchemy


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
 
 
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+...@googlegroups.com.

Message has been deleted

Balukrishnan

unread,
Mar 3, 2020, 7:41:59 AM3/3/20
to sqlalchemy
Thank you, my friend. Sorry for the incorrect example which I provide
Reply all
Reply to author
Forward
0 new messages