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
booleandefault 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@pro-ns.net
mark_wright@datacard.com