[web2py] Re: Building up a Query from nothing

2011-10-06 Thread howesc
how about use bruno's suggestion, but leave out the default at the top.  if 
the list of queries is empty when you get to the reduce step then set 
query=(db.table.id0) otherwise do the reduce?


[web2py] Re: Building up a Query from nothing

2011-10-06 Thread pbreit
I like the query = fragment approach better but am not sure how or if you 
can set up the default. Does anyone know if an extraneous db.item.id0 
impacts the query performance at all?

[web2py] Re: Building up a Query from nothing

2011-10-06 Thread howesc
if an extraneous db.item.id0 impacts the query performance at all?

depending on the system it definitely does for sufficiently complex 
queries.  on GAE, probably no effect, on oracle,mysql, postgres it depends 
on how you setup your indexes - you can probably write indexes so it has 
close to no effect, but then you have to allocate space to store that 
(potentially extra) index.

cfh


[web2py] Re: Building up a Query from nothing

2011-10-05 Thread Kevin Ivarsen
A couple other notes:

- I know I could start with a query that will return everything, like
db.person.id  0, but I'm worried about how that will interact with
queries that are optimized by an index that doesn't include the id
column

- An old trick when building up SQL WHERE statements as strings is to
start with WHERE 1=1 (which should get optimized away by the SQL
engine) and go from there. However, I couldn't find a way to make a
Query that evaluated to the equivalent of 1=1.

Cheers,
Kevin

On Oct 5, 1:39 pm, Kevin Ivarsen kivar...@gmail.com wrote:
 Hi everybody,

 I'm building a page that will search for rows in a database table
 based on optional URL parameters, or return all rows if no parameters
 are given. However, I'm having trouble finding a good way to build up
 the query without having an existing Query object to start with.
 Web2py currently lets me do something like this:

 q = (db.person.height  5)
 q = q  (db.person.height  6)
 db(q).select()

 But I'd like to be able to do something like this (in pseudocode):

 q = EmptyQuery(defaultTable=db.person)
 if request.vars.minheight:
   q = q  (db.person.height  request.vars.minheight)
 if request.vars.maxheight:
   q = q  (db.person.height  request.vars.maxheight)

 people = db(q).select()

 so that if no parameters are given, it will select all from db.person,
 but you can optionally filter by min and max height.

 Is there an easy way to do this in web2py?

 Thanks!
 Kevin