sql = """update {}data_sources set effective_end=(CURRENT_DATE -1) WHERE object_id='{}' and effective_start!=CURRENT_DATE and effective_end='{}'""" sql = sql.format(schema, ds.object_id, future_date) sqls.append(sql.replace("\n", " ")) sql = """insert into {}data_sources (object_id, source, file_type, load_method, field_delimiter, tshirt_size, delivery_frequency, contains_header_record, notify, effective_start, effective_end) values ('{}', '{}', '{}', '{}', '{}', '{}', '{}', {}, '{}', CURRENT_DATE, '{}') ON CONFLICT (object_id, effective_start) DO UPDATE SET source=excluded.source, file_type=excluded.file_type,load_method=excluded.load_method,field_delimiter=excluded.field_delimiter, tshirt_size=excluded.tshirt_size,delivery_frequency=excluded.delivery_frequency, contains_header_record=excluded.contains_header_record,notify=excluded.notify, effective_end=excluded.effective_end """ sql = sql.format(schema, ds.object_id, ds.source, ds.file_type, ds.load_method, ds.field_delimiter, ds.tshirt_size, ds.delivery_frequency, ds.contains_header_record, '{{"{}"}}'.format('","'.join(ds.notify)), future_date) sqls.append(sql.replace("\n", " ")) 43