when you want only one and the first better use .select(limitby=(0,1)) and
proper orderby, else you can be disappointed by performance...

2015-02-06 20:52 GMT+01:00 Anthony <[email protected]>:

> rows = db(query).select()
>
> In the above, "rows" is a Rows object, which acts like a list of Row
> objects. To extract a single Row object, you would do:
>
> row = rows[index]
>
> Specifically, to get the first Row, you would do:
>
> first_row = rows[0]
>
> rows.first() is simply equivalent to rows[0], except that if Rows happens
> to be empty, instead of raising an exception, it will simply return None.
> So, instead of doing:
>
> first_row = rows[0] if rows else None
>
> you can just do:
>
> first_row = rows.first()
>
> Anthony
>
>
>
> On Friday, February 6, 2015 at 2:18:13 PM UTC-5, Alex Glaros wrote:
>>
>> can someone please consolidate my knowledge or tell me where in
>> documentation this is explained
>>
>> the "first()" in this line below:
>>
>> this_message = db(db.InternalMessage.id == request.get_vars.filter).
>> select()*.first()*
>>
>> allows below to work in view:
>>
>>  {{=this_message.created_by.last_name}}
>>
>> if the ".first()" is removed leaving this:
>>
>> this_message = db(db.InternalMessage.id == request.get_vars.filter).
>> *select()*
>>
>> then view no longer works. First result is a single row, second result
>> can be many rows.
>>
>> What is this concept called?
>>
>> Is first result a dictionary and second result a row?
>>
>> I understand that there is unacceptable ambiguity in the 2nd result with
>> many possible rows but would like to know what the terms are called and
>> where documented so I can read about it.
>>
>> Is .first() the only/best way to get a value into a single var (when no
>> looping is necessary)?
>>
>> thanks
>>
>> Alex Glaros
>>
>  --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to