File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
src/acquisition/covid_hosp/common Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -186,9 +186,13 @@ def nan_safe_dtype(dtype, value):
186186
187187 num_columns = 2 + len (dataframe_columns_and_types ) + len (self .additional_fields )
188188 value_placeholders = ', ' .join (['%s' ] * num_columns )
189- columns = ', ' .join (f'`{ i .sql_name } `' for i in dataframe_columns_and_types + self .additional_fields )
189+ col_names = [f'`{ i .sql_name } `' for i in dataframe_columns_and_types + self .additional_fields ]
190+ columns = ', ' .join (col_names )
191+ updates = ', ' .join (f'{ c } =new_values.{ c } ' for c in col_names )
192+ # NOTE: list in `updates` presumes `publication_col_name` is part of the unique key and thus not needed in UPDATE
190193 sql = f'INSERT INTO `{ self .table_name } ` (`id`, `{ self .publication_col_name } `, { columns } ) ' \
191- f'VALUES ({ value_placeholders } )' # TODO: add ON DUPLICATE KEY UPDATE here for when we need to backfill yesterday's issue
194+ f'VALUES ({ value_placeholders } ) AS new_values ' \
195+ f'ON DUPLICATE KEY UPDATE { updates } '
192196 id_and_publication_date = (0 , publication_date )
193197 if logger :
194198 logger .info ('updating values' , count = len (dataframe .index ))
You can’t perform that action at this time.
0 commit comments