I got into this code while reviewing some repos, I know what lock does, know also that Redshift has a way of maintaining a current version of a table between queries using snapshots.
So the question is, does that lock at the begin of the transaction make any sense?
I think that it’s bringing more issues locking users than solutions.
Thanks!
begin transaction;
lock ${rsDestination};
create temp table stage (like ${rsDestination});
insert into stage
(${_.join(_.keys(schema), ', ')})
values ${formattedRecords.join(',n')};
delete from ${rsDestination}
using stage
where ${_.join(_.map(primaryKeys, (key) => `${rsDestination}.${key} = stage.${key}`), ' AND ')};
insert into ${rsDestination}
select * from stage;
end transaction;
drop table stage;`;
There are no apparent problems commenting on that line, I want to know if I’m missing something.
Thanks!