[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Anthony
I'm not sure you can do that. In order to access the mysum column in the result, you would do: row[mysum] Anthony On Sunday, February 26, 2012 11:05:59 AM UTC-5, Paul wrote: > > In the dal I'm selecting two summed fields and adding them together, > the column name in the set object ends up bei

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Alan Etkin
I know you want to modify the query, but you could replace the string when the rows are passed to a helper instance. On 26 feb, 13:05, Paul wrote: > In the dal I'm selecting two summed fields and adding them together, > the column name in the set object ends up being called > '(SUM(t_appointment.

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-26 Thread Paul
Thanks Anthony, That syntax works and I can use that to refer to the data, I could see that a row object had an '_extra' dict for the selected expressions but could not see that the data could be referred to be the name of the expression 'mysum' (its in there somewhere but not sure where!!) On Fe

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Anthony
> > That syntax works and I can use that to refer to the data, I could see > that a row object had an '_extra' dict for the selected expressions > but could not see that the data could be referred to be the name of > the expression 'mysum' (its in there somewhere but not sure where!!) > The b

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Paul
One last part of the puzzle, this all works ok at the command line with print row[mysum] but I cannot get the syntax for using this in a view for example:- controller DAL query:- def mileage(): mysum = db.t_appointment.miles_to.sum() +db.t_appointment.miles_from.sum() groupmm = db.t_a

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Anthony
The view only sees what you explicitly pass to it from the controller via the returned dictionary, so you would need to do: def mileage(): [snip] return dict(rows=rows, mysum=mysum, sql=db._lastsql) Or you could just do: return locals() which returns a dictionary of all the local

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Massimo Di Pierro
you need to put it in the dict so the view can see it. On Feb 27, 2:57 pm, Paul wrote: > One last part of the puzzle, this all works ok at the command line > with print row[mysum] but I cannot get the syntax for using this in a > view > > for example:- > > controller DAL query:- > def mileage():

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Paul
OK, I can get this to work in the view now, but it seems to be overly complicated, I have one dal statement to generate some rows, but if I want lots of sums, mins and max etc I then need to pass all these additional objects via the dict to the view!, when surely all this data should be just part o

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Massimo Di Pierro
I am not convinced that rows = db().select(db.table.field1.sum() as foo) + {{=row.foo}} is any simpler than foo = db.table.field1.sum() rows = db().select(foo) + {{=row[foo]}} The latter has the advantage that does not generate conflicts at the DB level. As far as I know the book is almost r

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Anthony
> > I am not convinced that > > rows = db().select(db.table.field1.sum() as foo) > + {{=row.foo}} > > is any simpler than > > foo = db.table.field1.sum() > rows = db().select(foo) > + {{=row[foo]}} > The problem is in the latter case, you have to pass foo to the view -- not a big deal wi

[web2py] Re: How do you define a column name on summed field (i.e. how to do the equivalent of an sql 'select ..... as colname'

2012-02-27 Thread Massimo Di Pierro
you can do: for row in rows: row.foo = row[foo] and then you do not have to pass it. On Feb 27, 10:40 pm, Anthony wrote: > > I am not convinced that > > > rows = db().select(db.table.field1.sum() as foo) > > +  {{=row.foo}} > > > is any simpler than > > > foo = db.table.field1.sum() > > rows =