I am using the following commands below in postgresql 9.1.3 to move data from a temp staging table to a table being used in a webapp (geoserver) all in the same db. Then dropping the temp table.
TRUNCATE table_foo;
INSERT INTO table_foo
SELECT * FROM table_temp;
DROP TABLE table_temp;
I want to wrap this in a transaction to allow for concurrency. The data-set is small less than 2000 rows and truncating is faster than delete.
- What is the best way to run these commands in a transaction?
- Is creating a function advisable or writing a UPSERT/MERGE etc in a CTE?
- Would it be better to DELETE all rows then bulk INSERT from temp table instead of TRUNCATE?
- In postgres which would allow for a roll back TRUNCATE or DELETE?
- The temp table is delivered daily via an ETL scripted in arcpy how could I automate the truncate/delete/bulk insert parts within postgres?
- I am open to using PL/pgsql, PL/python (or the recommended py for postgres)
Currently I am manually executing the sql commands after the temp staging table is imported into my DB.