From: | "Mark Wright" <mwright(at)pro-ns(dot)net> |
---|---|
To: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | How do I implement FIFO? |
Date: | 1999-05-27 23:12:17 |
Message-ID: | 000901bea896$60addb80$c62812ac@markw_compaq |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I want to be able to have multiple clients pulling single, mutually
exclusive records from a table in the same order that they were inserted
into the table. Imagine one group of people placing objects on a conveyor
belt, while at the other end another group of people are grabbing the first
item to come off the belt.
I think I know how to lay out the table:
create table XYZ
(
insert_seq_num serial,
is_processed boolean default FALSE,
some_data varchar(10)
);
Inserts are obvious. What I'm stumped by is how to write a SELECT that will
return the next available row in a way that two clients querying at the same
time can't grab the same one.
I think I can do it with temporary tables. I.e.
select * into temp ABC from XYZ
where is_processed = FALSE and
insert_seq_num = (select MIN(insert_seq_num)
from XYZ where is_processed = FALSE);
update XYZ set XYZ.is_processed = TRUE where exists
(select * from temp where ABC.insert_seq_num = XYZ.insert_seq_num);
select * from temp;
commit;
But even if that would work, temp tables aren't supported in 6.4. Is there
another way to do this without using temp tables?
Mark
---
Mark Wright
mwright(at)pro-ns(dot)net
mark_wright(at)datacard(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | George Wadsworth | 1999-05-28 00:44:12 | using variable in nextval |
Previous Message | Andrei de Oliveira Mosman | 1999-05-27 21:04:23 |