Skip to content

Commit e306ec1

Browse files
committed
Enable upsert of consensus_genome records with ON CONFLICT clause
The upsert_genome function was only performing inserts. Adding ON CONFLICT clause to perform a "non-updating" update and return the existing record id.
1 parent 5929a34 commit e306ec1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/seattleflu/id3c/cli/command/etl/clinical.py

+4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ def upsert_genome(db: DatabaseSession, sample: MinimalSampleRecord, organism: Or
213213
insert into warehouse.consensus_genome (sample_id, organism_id)
214214
values (%(sample_id)s, %(organism_id)s)
215215
216+
on conflict (sample_id, organism_id) where sequence_read_set_id is null do update
217+
set sample_id = excluded.sample_id,
218+
organism_id = excluded.organism_id
219+
216220
returning consensus_genome_id as id, sample_id, organism_id
217221
""", data)
218222

0 commit comments

Comments
 (0)