Re: [SQL] idiom to move records?
От | jwieck@debis.com (Jan Wieck) |
---|---|
Тема | Re: [SQL] idiom to move records? |
Дата | |
Msg-id | m0zXjTi-000EBPC@orion.SAPserv.Hamburg.dsh.de обсуждение исходный текст |
Ответ на | idiom to move records? (Leslie Mikesell <les@Mcs.Net>) |
Ответы |
Re: [SQL] idiom to mv recs => [NEW] bleeding lock?
|
Список | 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@debis.com (Jan Wieck) #
В списке pgsql-sql по дате отправления: