If you want to get rid of the orderby, do: db(db.mytable.id == someid).select(db.mytable.id, limitby=(0, 1),orderby_on_limitby =False)
When you specify a limitby, by default it will orderby the PK (or add the PK to the orderby). The reason for this is to ensure a consistent ordering if you repeat the query or are using the limitby for pagination purposes (otherwise, successive queries are not guaranteed to return results in the same order). Anthony On Wednesday, January 22, 2014 7:35:22 AM UTC-5, Jayadevan M wrote: > > Here is how it is now .. > > 1) cond = db.mytable(id=someid) > generates > SELECT <all columns> FROM mytable WHERE (id = someid) LIMIT 1 OFFSET 0; > > 2) cond = db(db.mytable.id==someid).select(db.mytable.id,limitby=(0, 1)) > generates > SELECT <mycolumn> FROM mytable WHERE (id = someid) ORDER BY pk LIMIT 1 > OFFSET 0; > > What I would like to have is > > SELECT <mycolumn> FROM mytable WHERE (id = someid) LIMIT 1 ; > > On Wednesday, January 22, 2014 5:36:00 PM UTC+5:30, Jayadevan M wrote: >> >> Sorry. It works (I got something wrong earlier) but the limit has gone >> away. I just have to ensure that there is ay least one record. >> >> >> On Wed, Jan 22, 2014 at 5:28 PM, Jayadevan M >> <maymala....@gmail.com<javascript:> >> > wrote: >> >>> I tried that. I get the error - >>> <type 'exceptions.AttributeError'> 'Row' object has no attribute 'select' >>> By the way, the "=" works. Additional information, this function is >>> under modules. Do I have to imprt something to make the select construct >>> work? >>> >>> >>> On Wed, Jan 22, 2014 at 5:22 PM, Johann Spies >>> <johann...@gmail.com<javascript:> >>> > wrote: >>> >>>> Oops. That should be >>>> cond = db(db.mytable.id==someid).select(db.mytable.id) >>>> >>>> >>>> On 22 January 2014 13:50, Johann Spies <johann...@gmail.com<javascript:> >>>> > wrote: >>>> >>>>> cond = db.mytable(id=someid).select(db.mytable.id) >>>>> >>>>> Regards >>>>> Johann >>>>> >>>>> >>>>> On 22 January 2014 10:50, Jayadevan M <maymala....@gmail.com<javascript:> >>>>> > wrote: >>>>> >>>>>> I am checking for existence of record in a table >>>>>> >>>>>> cond = db.mytable(id=someid) >>>>>> if not cond : >>>>>> do something >>>>>> >>>>>> This works fine. The query executed selects *all* columns and adds >>>>>> LIMIT 1 OFFSET 0; The LIMIT and OFFSET are OK. Since I want to just >>>>>> check >>>>>> for existence of a record, how can I rewrite this so that we have only >>>>>> the >>>>>> id column selected? I am trying to avoid a table scan and have just an >>>>>> index scan. >>>>>> >>>>>> -- >>>>>> Resources: >>>>>> - http://web2py.com >>>>>> - http://web2py.com/book (Documentation) >>>>>> - http://github.com/web2py/web2py (Source code) >>>>>> - https://code.google.com/p/web2py/issues/list (Report Issues) >>>>>> --- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "web2py-users" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to web2py+un...@googlegroups.com <javascript:>. >>>>>> For more options, visit https://groups.google.com/groups/opt_out. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Because experiencing your loyal love is better than life itself, >>>>> my lips will praise you. (Psalm 63:3) >>>>> >>>> >>>> >>>> >>>> -- >>>> Because experiencing your loyal love is better than life itself, >>>> my lips will praise you. (Psalm 63:3) >>>> >>>> -- >>>> Resources: >>>> - http://web2py.com >>>> - http://web2py.com/book (Documentation) >>>> - http://github.com/web2py/web2py (Source code) >>>> - https://code.google.com/p/web2py/issues/list (Report Issues) >>>> --- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "web2py-users" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/web2py/XYeLmZjQ6fY/unsubscribe. >>>> To unsubscribe from this group and all its topics, send an email to >>>> web2py+un...@googlegroups.com <javascript:>. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>> >>> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.