SQL:UPSERT/upsert语句模板常用
python的upsert和pymysql结合使用
insert_sql = "insert into supervision.kafka_consume_partition_offset (appkey, used_appkey, partition, offset, remark, update_time) values (%s, %s, %s, %s, %s, %s) on duplicate key update offset=values(offset), remark=values(remark), update_time=values(update_time)"
pycharm要复制为文本
def upsert_event_data():
upsert_sql = f"insert into `{MYSQL_DB}`.`{MYSQL_EVENT_TABLE}` " \
f"(module_name, trigger_action, event_name, event_status, statistical_indicators, " \
f"create_time, update_time) values (%s, %s, %s, %s, %s, %s, %s) on " \
f"duplicate key update " \
f"module_name=values(module_name), " \
f"trigger_action=values(trigger_action), " \
f"event_name=values(event_name), " \
f"event_status=values(event_status), " \
f"statistical_indicators=values(statistical_indicators), " \
f"update_time=values(update_time)"