[sqlalchemy] Re: Creating SQL Expression

2009-02-26 Thread Gunnlaugur Thor Briem
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[

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
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: [

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
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

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Gunnlaugur Thor Briem
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))

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Gunnlaugur Thor Briem
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

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread King Simon-NFHD78
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

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
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

[sqlalchemy] Re: Creating SQL Expression

2009-02-25 Thread Ashish Bhatia
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',