I have a main table called repos, and a temp table from a csv, that I want to match the name, and update a value with the new value from the temp table. My code works, but is slow.
CREATE TEMP TABLE tmp(name text, language text);
COPY tmp FROM 'path/to/csv';
UPDATE repos
SET language = x.language
FROM (
SELECT * FROM tmp) x
WHERE repos.name = x.name
First, the subquery is unnecessary. It doesn't affect performance but it is awkward:
UPDATE repos
SET language = x.language
FROM tmp x
WHERE repos.name = x.name;
For this query, you want an index on tmp(name, language)
:
create index idx_tmp_name_language on tmp(name, language);
Creating an index is usually faster after the table has been populated (as opposed to creating the index first and then loading the table).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments