SimpleDB Select syntax

253 views
Skip to first unread message

David Arthur

unread,
Jun 1, 2009, 5:45:56 PM6/1/09
to boto-users
For the life of me I cannot get SimpleDB selects working. I have the
old query syntax working fine, but I need to use the select.

Old query language: mydomain.query("['title' = 'foobar']")

And I need that in the select syntax. Something like: mydomain.select
("select * from mydomain where title = 'foobar'") but this doesn't
work. Does anyone have some examples of the select syntax in use with
boto?

Thanks

Mitchell Garnaat

unread,
Jun 1, 2009, 6:49:13 PM6/1/09
to boto-...@googlegroups.com
You syntax looks okay.  I usually use single quotes around the entire query and double-quotes inside the string but either should work.  Try using backquotes around the attribute name, like this:

'select * from mydomain where `title`="foobar"'

Mitch

David Arthur

unread,
Jun 2, 2009, 2:06:29 PM6/2/09
to boto-users
I am continued to get errors. I'm not sure if it matters, but I'm
getting back InvalidQueryExpression errors, even though this is a
Select expression (not sure if SimpleDB distinguishes). Here is my
very very simple query.

select * from mydomain

where mydomain is the name of the SimpleDB domain I'm working with. Do
be clear, here is the python code I am executing this with:

sdb_conn = SDBConnection
(config.aws.access_key_id,config.aws.secret_access_key)
domain = sdb_conn.get_domain("mydomain")
items = domain.select('select * from mydomain where
`item_id`="293773"')

The above code does not work, the following does:

sdb_conn = SDBConnection
(config.aws.access_key_id,config.aws.secret_access_key)
domain = sdb_conn.get_domain("mydomain")
items = domain.query("['item_id' = '293773']")

For the first snippet, I get:
SDBResponseError: SDBResponseError: 400 Bad Request <?xml
version="1.0"?> <Response><Errors><Error><Code>InvalidQueryExpression</
Code><Message>The specified query expression syntax is not valid.</
Message><BoxUsage>0.0000137200</BoxUsage></Error></
Errors><RequestID>203a41ba-b446-75c5-b388-fb0ecefd51bb</RequestID></
Response>

I am utterly confused.
-David

Mitchell Garnaat

unread,
Jun 2, 2009, 2:38:19 PM6/2/09
to boto-...@googlegroups.com
Which version of boto are you using?

I tried typing in your example and it works for me.  See output below.  This is in the latest subversion code which is basically the same as 1.7a in terms of the SimpleDB code.

Mitch



In [1]: import boto
In [2]: c = boto.connect_sdb()
In [3]: d = c.create_domain('mydomain')
In [4]: d.put_attributes('itemname1', {'item_id' : '293773'})
Out[4]: True
In [6]: d.select('select * from mydomain where `item_id`="293773"')
Out[6]: <generator object at 0xe7cc60>
In [7]: _.next()
BoxUsage: 0.0000228636
Out[7]: {u'item_id': u'293773'}

David Arthur

unread,
Jun 2, 2009, 3:57:29 PM6/2/09
to boto-users
As to avoid flooding this thread, I'll pastebin my console output.

http://pastebin.ca/1445305

It appears it is only when I call the next() method of the "select"
resultset generator that I have problems. I included the equivalent
"query" to show that the item does in fact exist.

David Arthur

unread,
Jun 2, 2009, 4:02:36 PM6/2/09
to boto-users
I am running boto 1.7. I installed with easy_install

Mitchell Garnaat

unread,
Jun 2, 2009, 4:02:54 PM6/2/09
to boto-...@googlegroups.com
Yeah, the query isn't actually sent to SimpleDB until you call next().

Mitchell Garnaat

unread,
Jun 2, 2009, 4:05:40 PM6/2/09
to boto-...@googlegroups.com
Well, that's just freaky.  I can run what seems to me to be exactly the same query against a domain of the same name and it works.  I need to dig in a little and see if I can figure out what's going on.

David Arthur

unread,
Jun 2, 2009, 4:20:39 PM6/2/09
to boto-users
Solved! My domain name had a dash in it. I needed to wrap it with
backquotes.

I knew it wasn't boto. :)

So here is my finally working select query:

domain.select("select * from `my-domain` where `item_id` = '293760'")

Thanks for the help Mitch
-David

Mitchell Garnaat

unread,
Jun 2, 2009, 4:26:08 PM6/2/09
to boto-...@googlegroups.com
Oh, you dog.  You didn't tell me the domain name 8^)

No wonder mine worked.  Yeah, I've found, when it doubt, backquote it.
Reply all
Reply to author
Forward
0 new messages