SelectResultSet generator ignoring LIMIT clause

49 views
Skip to first unread message

David Arthur

unread,
Jun 4, 2009, 11:52:10 PM6/4/09
to boto-users
When I execute a select request on a SimpleDB domain, it always
returns all the results instead of how many I specified by a "LIMIT"
clause.

Example: select * from `mydomain` limit 1

>> import boto
>> c = boto.connect_sdb()
>> d = c.get_domain('mydomain')
>> items = d.select("select * from `mydomain` limit 1")
>> for item in items:
... print item

Just continues paging through results. With the query method, you can
specify max_items to return. Could we see this implemented for select
as well? For now I'm manually breaking the generated after my
specified limit has been reached.

Mitchell Garnaat

unread,
Jun 5, 2009, 12:15:06 AM6/5/09
to boto-...@googlegroups.com
Apparently, SimpleDB interprets the "limit N" clause of the query to mean "how many should I return in one page" not "how many should I return altogether" so if you pass in "limit 10" you will see the results chunked in batches of 10 but each result returned will contain a NextToken element which triggers the resultset to go fetch more results.

Short of actually parsing the select string in boto (and I'm really not crazy about that idea) I'm not exactly sure how to solve this one.  Suggestions?

Mitch

David Arthur

unread,
Jun 5, 2009, 9:59:55 AM6/5/09
to boto-users
How about do it like the query method does it: a max_items parameter

>> import boto
>> c = boto.connect_sdb()
>> d = c.get_domain('mydomain')
>> items = d.select("select * from `mydomain`",max_items=1)

David Arthur

unread,
Jun 12, 2009, 2:36:04 PM6/12/09
to boto-users
Here's how I'm getting around it for the time being

limit = 10
items = d.select("select * from `mydomain` limit %s" % limit)
for i in range(limit):
item = items.next()
...
Reply all
Reply to author
Forward
0 new messages