def build_insert_sql(insert_data_dict):
insert_fields = list(insert_data_dict.keys())
insert_values = list(insert_data_dict.values())
insert_values = [value if value is not None else 'NULL' for value in insert_values]
insert_field_str = ', '.join(insert_fields)
insert_values_str = ', '.join(f"'{value}'" if value is not None else str(value) for value in insert_values)
insert_sql_string = f"INSERT INTO table_name ({insert_field_str}) VALUES ({insert_values_str})"
insert_sql_string = insert_sql_string.replace("\'NULL\'", "NULL")
return insert_sql_string
insert_data = {
'aa': 1,
'bb': 'b',
'receipt_no': None
}
insert_sql = build_insert_sql(insert_data)
print(insert_sql)
08-05
2819