Am looking to delete a vast amount of data in our database, we are not sure where to place the deleted data for now but to have a separate copy is what we are looking to do.
I explored using a CTE originally but there are some concerns about the use of a CTE for such large data so have opted for a temp table but am having difficulty getting it working.
Am also trying to wrap it in a transaction so we have the option of rolling back should we want to:
begin; -- typically faster and safer wrapped in a single transaction
CREATE TEMP TABLE tmpold AS ( ERROR: syntax error at or near "t" Position: 51)
SELECT t.*
--into temporary table tmpold (also tried this but ERROR: syntax error at or near "t" Position: 51
FROM play t
where t.play_created_on > NOW() - interval '1 years';
delete t.* from play t
inner join tmpold on t.play_id = tmpold.play_id;
select count (*) from tmpold
ROLLBACK;
Cant understand why it is not working, I want to select a set of values from a play table into a temp table and then delete the data from the play table using the values from the temp table.
Not sure whether the temp table is the correct way, I want to retain the deleted data from the play table in a separate table until we can decide what we do with it.
DELETEstatement.