>
> Is there a handy way to move a set of records to a different
> table in sql? I'd like to do this based on a WHERE clause
> and have it work atomically such that it will not lose new
> records added between the step that copies to the other table
> and deleting the copied records.
Use a transaction and lock the source table first.
BEGIN TRANSACTION;
LOCK TABLE src_table;
INSERT INTO dest_table SELECT * FROM src_table
WHERE ...;
DELETE FROM src_table WHERE ...;
COMMIT TRANSACTION;
No other backend can add, modify or remove rows to/in/from
src_table while you have a lock on it.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#======================================== jwieck@debis.com (Jan Wieck) #