On 29 July 2011 14:01, Ken Wesson <kwess...@gmail.com> wrote:
> On Fri, Jul 29, 2011 at 7:41 AM, László Török <ltoro...@gmail.com> wrote:
>> Hi,
>>
>> is there a way to execute multiple select queries on a table using clojureql
>> in a transaction?
>>
>> sg. like
>>
>>    (with-results [res1 query1
>>                         res2 query2]
>>        .. do sg)
>>
>> and res1 and res2 would be taken from a same consistent snapshot.
>
> If you run two separate queries, I expect the database server will see
> them as two separate transactions, and may interleave some other,
> mutating transaction between them, so they won't in that case be taken
> from a consistent snapshot.

Well, I suppose it you use SELECT FOR UPDATE/SHARE it should not allow
changes between them, but I've never used SELECT FOR UPDATE or SHARE,
so perhaps I'm wrong or I'm misunderstanding your point.

e.g.

http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE

http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html

So, I think this should work:

BEGIN;
SELECT ... FOR SHARE;
SELECT ...;
COMMIT;

Whether it's possible to do that with ClojureQL I have no idea.

> You'd need to have a single query to the DB, which will run as a
> single transaction, generate both res1 and res2. I'm not sure if that
> will always be possible; my SQL-fu is a little rusty.

-- 
Michael Wood <esiot...@gmail.com>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to