{"version":"1.0","type":"rich","title":"How to compile an INSERT ... ON DUPLICATE KEY UPDATE with SQL Alchemy with support for a bulk insert.","description":"This example demonstrates a custom SQLAlchemy construct that compiles an `INSERT ... ON DUPLICATE KEY UPDATE` statement for MySQL, enabling efficient bulk upserts. The `Upsert` class extends `sqlalchemy.sql.expression.Insert`, and a `@compiles` decorator registers a MySQL-specific compiler function that transforms the insert into an upsert by appending the `ON DUPLICATE KEY UPDATE` clause with `VALUES()` references. The code detects auto-increment primary keys to use `LAST_INSERT_ID()` for correct ID handling, and it supports both single-row and multi-row parameter sets.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-9fe4888ccf6caa8e032cba15e1940ca6?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}