LIMIT and OFFSET in Postmodern

Tagged as LISP, Programming

Written on 2010-04-25 17:58:09

I've been using the Postmodern library in Common Lisp to access PostgresQL databases of late and it's been a pretty good experience.

That said, I had a little trouble using LIMIT and OFFSET to get DAO objects and wanted to put an example online in case anyone else has trouble with this. Future Postmoderners, May Google protect you.

You'll want to use query-dao instead of select-dao and wrap the limit around a select statement. It winds up looking something like this:

(query-dao 'card
(:limit (:select (:distinct 'name) :from 'card) 10 0))

In this example, we're selecting the first 10 rows (that are distinct by name) from the card table. Obviously, you could use '* instead of (:distinct 'name) to select from all rows.

That's not much of a post but here it is. Once I'm through finals I'll try to start posting a bit more regularly. Then again, I'll be moving once in May and once in June so we'll see what happens.
comments powered by Disqus

Unless otherwise credited all material Creative Commons License by Brit Butler