From: | Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il> |
---|---|
To: | Leslie Mikesell <les(at)Mcs(dot)Net> |
Cc: | pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] idiom to move records? |
Date: | 1998-10-26 09:34:41 |
Message-ID: | l03110701b259f11ba64d@[147.233.159.109] |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
At 7:31 +0200 on 26/10/98, Leslie Mikesell wrote:
> 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.
Do it in a transaction, then. Assuming that the target table is defined
(not a temporary table you create ad-hoc), you do:
BEGIN TRANSACTION;
LOCK TABLE source_table;
INSERT INTO target_table (col1, col2, col3)
SELECT (expr1, expr2, expr3)
FROM source_table
WHERE <where condition here>;
DELETE FROM source_table
WHERE <where condition here>;
COMMIT;
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 1998-10-26 10:02:22 | Re: [SQL] idiom to move records? |
Previous Message | Mike Meyer | 1998-10-26 08:19:12 | Help on extensended attribute types? |