You can get the column object from the string, using:
xyz.c[column_name]
Do you mean that this:
columns = [a,b,c]
operators = ['+','-']
should result in xyz.c.a + xyz.c.b - xyz.c.c ?
To do that, something like this works:
columns = [a,b,c]
operators = ['+','-']
colnames_and_ops = zip(columns[
27;, a, b)
>
> I think that should work.
>
> Simon
>
> > -Original Message-
> > From: sqlalchemy@googlegroups.com
> > [mailto:sqlalch...@googlegroups.com] On Behalf Of Ashish Bhatia
> > Sent: 25 February 2009 13:26
> > To: sqlalchemy
> > Subject: [
This works fine
But in the mine case
columns = [a,b,c]
operator = ['+','-']
comes in the list
And it can go to n number.
So while adding it creates a problem
My approach
looping on columns i append it in to the table and hence making the
object
i can join them with operator to form the a+b-c
Whoops, premature send, sorry. For an arbitrary list of columns, such as t.c
(the column collection) or other SQL selectables, such as the above binary
expressions, you can use sum(columns). E.g.:
t = Table('bobloblaw', MetaData(), Column('a', Integer), Column('b',
Integer), Column('c', Integer))
You can sum the column objects directly, a+b, producing a
sqlalchemy.sql.expression._BinaryExpression object.
t = Table('bobloblaw', MetaData(), Column('a', Integer), Column('b',
Integer), Column('c', Integer))
t.c.a + t.c.b
# evaluates to
print t.c.a + t.c.b
# bobloblaw.a + bobloblaw.b
On Wed
sum_column = combine_columns('+', a, b)
I think that should work.
Simon
> -Original Message-
> From: sqlalchemy@googlegroups.com
> [mailto:sqlalch...@googlegroups.com] On Behalf Of Ashish Bhatia
> Sent: 25 February 2009 13:26
> To: sqlalchemy
> Subject: [sqla
The problem is still their.
The two seprate list of
columns = List of sqlalchem object
operator = ['+'','-']
using join to join them will convert the columns object to string
which is not desirable.
Any way to fix this.
On Feb 25, 3:54 pm, Ashish Bhatia wrote:
> sorry its resolved and working
sorry its resolved and working
On Feb 25, 12:20 pm, Ash wrote:
> Hello ,
>
> I am trying to make query like
>
> select (a+b) from xyz;
>
> to do this
>
> xyz = sqlalchemy.Table('xyz',metadata)
>
> a = sqlalchemy.Column('a', sqlalchemy.Integer)
> xyz.append_column(a)
> b = sqlalchemy.Column('b',