From: | jwieck(at)debis(dot)com (Jan Wieck) |
---|---|
To: | les(at)Mcs(dot)Net (Leslie Mikesell) |
Cc: | pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] idiom to move records? |
Date: | 1998-10-26 10:02:22 |
Message-ID: | m0zXjTi-000EBPC@orion.SAPserv.Hamburg.dsh.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
>
> 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(at)debis(dot)com (Jan Wieck) #
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Good | 1998-10-26 13:18:48 | Re: [SQL] idiom to mv recs => [NEW] bleeding lock? |
Previous Message | Herouth Maoz | 1998-10-26 09:34:41 | Re: [SQL] idiom to move records? |