Skip to content

feat(parser): support MySQL 8.0.19+ INSERT row alias syntax#33

Closed
paultyng wants to merge 2 commits into
sqlc-dev:mainfrom
paultyng:2026-04-30-1726-update-to-latest-mysql-syntax-in-auth-token
Closed

feat(parser): support MySQL 8.0.19+ INSERT row alias syntax#33
paultyng wants to merge 2 commits into
sqlc-dev:mainfrom
paultyng:2026-04-30-1726-update-to-latest-mysql-syntax-in-auth-token

Conversation

@paultyng

@paultyng paultyng commented May 1, 2026

Copy link
Copy Markdown

Replays pingcap/tidb#67920 into marino. Partial fix for #22.

  • Adds RowAlias / ColumnAliases to ast.InsertStmt and InsertRowAliasOpt grammar on INSERT ... VALUES and INSERT ... SET.
  • Rejects the alias on REPLACE (shared InsertValues rule).
  • Parser-only. Planner/executor alias resolution is out of scope.

Not covered (follow-up): the INSERT ... SELECT ... AS new form from #22. Adding it requires extending the four Select-branched alternatives of InsertValues and may introduce grammar ambiguity with SELECT's own AS table alias — left for a separate PR.

paultyng and others added 2 commits May 1, 2026 09:13
Add parsing support for the `AS row_alias[(col_alias, ...)]` clause
in INSERT ... VALUES and INSERT ... SET statements, as introduced in
MySQL 8.0.19 (WL #6312) and required since VALUES() was deprecated
in MySQL 8.0.20.

Examples:
  INSERT INTO t VALUES (1,2) AS new ON DUPLICATE KEY UPDATE b = new.b;
  INSERT INTO t VALUES (1,2) AS new(m,n) ON DUPLICATE KEY UPDATE b = m;
  INSERT INTO t SET a=1,b=2 AS new ON DUPLICATE KEY UPDATE b = new.a;

This is a parser-only change; planner/executor support for resolving
the alias references is not included. The INSERT ... SELECT form of
the row alias is not yet supported.

Replays pingcap/tidb#67920. Refs sqlc-dev#22.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
REPLACE does not support the AS row_alias syntax in MySQL.
Since ReplaceIntoStmt reuses InsertValues, add a check to
reject any row alias parsed via that shared grammar rule.

Replays pingcap/tidb#67920. Refs sqlc-dev#22.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@paultyng

paultyng commented May 4, 2026

Copy link
Copy Markdown
Author

@kyleconroy wasn't sure where things stood with accepting PRs here while you are forking this. I'm working in a MySQL codebase so was trying to get the newer upsert functionality in to it via sqlc. I had opened this PR on tidb, but figured I should also bring it here.

@kyleconroy

Copy link
Copy Markdown
Contributor

@paultyng appreciate the pull request, but I'm trying something different on this repository. I'm going to be authoring all of the PRs with Claude. That said, please add any additional requirements or example queries to #22 so that I can make sure the final change supports everything you need.

@paultyng

Copy link
Copy Markdown
Author

No problem, I'll update 22 with all the context (this was written with Claude already so it will probably look about the same 😂 )

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.

2 participants