Reputation: 25
I have two csv files file1.csv
and file2.csv
I load those files in
two tables in a database 'table1
' and 'table2
'. table1
contains
two columns
, those columns use table2
columns to calculate their
values, and after that the row of table2
can be deleted because it
used just to update
table1
.
My question is:
Which solution is better:
Upvotes: 0
Views: 123
Reputation: 656942
TEMPORARY
staging table table2
. Temporary tables perform much better (and are not persisted).COPY
file2.csv into it.UPDATE
table1.The temporary table is dropped at the end of the session automatically. Code example here:
How to tell if record has changed in Postgres
For repeated use, you might keep an empty persisted table2
as template for the temporary table like demonstrated in the linked answer.
Or even put all of it into a plpgsql function (that's what I would do).
Upvotes: 1
Reputation: 9776
Another option is to use the file_fdw FOREIGN DATA WRAPPER to read the file2.csv from within the db (without having to load it) and insert the calculated results into table1
. This assumes that you are using Postgres 9.1+, and that your file2.csv isn't too big. The suggestion from Erwin is probably the most useful solution, however.
Upvotes: 1