Skip to content

Support MySQL 8 row/column alias syntax in executemany INSERT regex#1235

Merged
methane merged 5 commits into
mainfrom
copilot/fix-regular-expression-executemany
May 14, 2026
Merged

Support MySQL 8 row/column alias syntax in executemany INSERT regex#1235
methane merged 5 commits into
mainfrom
copilot/fix-regular-expression-executemany

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

Cursor.executemany() fast-path parsing for INSERT ... VALUES ... ON DUPLICATE KEY UPDATE did not accept MySQL 8.0.19+ alias syntax (VALUES (...) AS alias), so these statements could miss bulk-insert optimization. This updates the parser to recognize the newer syntax while preserving existing behavior.

  • Regex update in pymysql/cursors.py

    • Extend RE_INSERT_VALUES suffix parsing to accept:
      • optional AS <row_alias>
      • optional AS <row_alias>(<col_alias>, ...)
      • followed by optional ON DUPLICATE ...
    • Keep existing INSERT|REPLACE ... VALUES (...) grouping semantics used by executemany().
  • Compatibility preserved

    • Existing legacy upsert style using VALUES(col) in ON DUPLICATE KEY UPDATE remains supported.
  • Focused coverage in pymysql/tests/test_cursor.py

    • Add regex assertions for:
      • VALUES (...) AS new ON DUPLICATE KEY UPDATE ...
      • VALUES (...) AS new(c1,c2,...) ON DUPLICATE KEY UPDATE ...
      • legacy ON DUPLICATE KEY UPDATE ... VALUES(...)
m = pymysql.cursors.RE_INSERT_VALUES.match(
    "INSERT INTO t1 (a,b,c) VALUES (%s,%s,%s) AS new "
    "ON DUPLICATE KEY UPDATE c = new.a + new.b"
)

Copilot AI changed the title [WIP] Fix regular expression for new alias syntax in executemany Support MySQL 8 row/column alias syntax in executemany INSERT regex May 14, 2026
Copilot AI requested a review from methane May 14, 2026 10:08
@methane methane marked this pull request as ready for review May 14, 2026 14:47
@methane methane merged commit 097fad6 into main May 14, 2026
23 of 25 checks passed
@methane methane deleted the copilot/fix-regular-expression-executemany branch May 14, 2026 16:31
methane pushed a commit that referenced this pull request May 15, 2026
- update `CHANGELOG.md` for `v1.2.0` release preparation
- add `Release date: TBD`
- add changelog entries for user-visible changes since `v1.1.3` (#1234,
#1235, #1236, #1237)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regular expression in executemany doesn't support new alias syntax for INSERT ... ON DUPLICATE KEY UPDATE

2 participants