Re: [GENERAL] easy task: concurrent select-updates

2009-09-05 Thread Andy Colson
Nickolay wrote: Kevin McConnell wrote: CREATE OR REPLACE FUNCTION public.getmsg() RETURNS integer LANGUAGE plpgsql AS $function$ declare rec record; begin for rec in select id from msg where busy =alse order by id loop update msg set busy =rue where id = rec.id and bus

Re: [GENERAL] easy task: concurrent select-updates

2009-09-04 Thread Nickolay
Andy Colson wrote: Kevin McConnell wrote: I think you could also do something roughly similar in a statement by using a RETURNING clause on the update, such as: update msg set busy = true where id = (select min(id) from msg where busy = false) returning *; I had thought of that, but you'd

Re: [GENERAL] easy task: concurrent select-updates

2009-09-03 Thread Nickolay
Kevin McConnell wrote: CREATE OR REPLACE FUNCTION public.getmsg() RETURNS integer LANGUAGE plpgsql AS $function$ declare rec record; begin for rec in select id from msg where busy =alse order by id loop update msg set busy =rue where id = rec.id and busy = false;

Re: [GENERAL] easy task: concurrent select-updates

2009-09-03 Thread Andy Colson
Kevin McConnell wrote: CREATE OR REPLACE FUNCTION public.getmsg() RETURNS integer LANGUAGE plpgsql AS $function$ declare rec record; begin for rec in select id from msg where busy = false order by id loop update msg set busy = true where id = rec.id and busy = false;

Re: [GENERAL] easy task: concurrent select-updates

2009-09-03 Thread Kevin McConnell
> CREATE OR REPLACE FUNCTION public.getmsg() RETURNS integer LANGUAGE plpgsql > AS $function$ > declare >       rec record; > begin >       for rec in select id from msg where busy = false order by id loop >               update msg set busy = true where id = rec.id and busy = false; >            

Re: [GENERAL] easy task: concurrent select-updates

2009-09-03 Thread Andy Colson
Nickolay wrote: one important addition: the message cannot be removed from queue table until it is transmitted, so DELETE is not an option :) Hi All, I have a trivial task. There is a table with messages queue, let's say "msg_queue". There are a few processes and each of them is taking one mes

Re: [GENERAL] easy task: concurrent select-updates

2009-09-03 Thread Nickolay
one important addition: the message cannot be removed from queue table until it is transmitted, so DELETE is not an option :) Hi All, I have a trivial task. There is a table with messages queue, let's say "msg_queue". There are a few processes and each of them is taking one message from this t

[GENERAL] easy task: concurrent select-updates

2009-09-03 Thread Nickolay
Hi All, I have a trivial task. There is a table with messages queue, let's say "msg_queue". There are a few processes and each of them is taking one message from this table at a time to transmit into communication channel. I've done it my way, but I have postgresql's messages about deadlocks a