select ... for update limit 1

From: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: select ... for update limit 1
Date: 2001-02-19 03:30:26
Message-ID: 3.0.5.32.20010219113026.008a8ea0@192.228.128.13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

What should the official behaviour of
select ... for update limit 1 be?

This is one of the methods I'm considering for multiple worker processes to
each select a _different_ task from the same "todo queue" table.

e.g.
begin;
select taskid from todoqueue where assignedpid=0 for update limit 1;
update todoqueue set assignpid=$mypid where taskid=$taskid;
commit;

Would it be better to lock the table instead? Locking the table would stop
the scheduler from inserting new tasks to the queue table, which is not
desirable.

Right now select for update limit 1 seems to lock all rows in the where
clause, not just retrieved rows. This is ok (would be nicer if it was just
one, but that's pushing it ;) ), but I suspect I'm approaching a less
travelled region with this :). Any potential gotchas I should look out for?

Thanks,
Link.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message newsreader 2001-02-19 03:46:25 Re: I've followed the faq and still getting too many clients errr
Previous Message newsreader 2001-02-19 03:26:23 Re: I've followed the faq and still getting too many clients errr