Thursday, February 12, 2009

SimpleDB and sorting comments


I was chatting with Dave Wilcox as I was working on my lab tonight and he is a life saver. (A wild cherry one, I would guess.) Anyway, as I was working on my query for comments he gave me the greatest tip ever!

If you want to sort by something in your SimpleDB query, it has to be referenced in the query.

For example, if I wanted to sort by coolness in my made up SimpleDB domain, you might think the query "['submitdate' > 'some param'] sort 'coolness' desc". This query seems to make sense to me and probably everyone who has ever used SQL. Yet, you won't get nothin' back from SimpleDB. You need to make sure you include whatever you want to sort by in your query: ['submitdate' > 'some param'] intersection ['coolness' = 'something that is always true' sort 'coolness' desc". Now SimpleDB will give you back all the results your heart or query desires. I thought it was very odd so I just wanted to warn everyone else! Good luck.

Picture from : http://ecx.images-amazon.com/images/I/519DTFXWQ6L._SL500_AA280_PIbundle-12,TopRight,0,0_AA280_SH20_.jpg

2 comments:

  1. I don't know of the least-common-denominator database systems require it, but generally in a traditional SQL database (which SimpleDB tries to be, kinda, and isn't) you need to reference your sort fields as well. It's not just SimpleDB.

    ReplyDelete
  2. Thanks Jeremy, I was having trouble with that as well. ;)

    ReplyDelete