Skip to content

MySQL 8.0.19+ ... AS alias ... ON DUPLICATE KEY syntax parsing problem #2789

Closed

Description

@jessepeterson

Version

1.22.0

What happened?

MySQL 8.0.19 deprecated the former ON DUPLICATE KEY syntax for the newer column reference style but sqlc doesn't seem to like it.

Note the old style VALUES() is now deprecated:

The use of VALUES() to refer to the new row and columns is deprecated beginning with MySQL 8.0.20, and is subject to removal in a future version of MySQL. Instead, use row and column aliases, as described in the next few paragraphs of this section.

Relevant log output

$ sqlc generate
# package sqlc
query.sql:20:24: syntax error near "as new"

Database schema

CREATE TABLE dep_names (
  mykey VARCHAR(255) NOT NULL,
  a VARCHAR(255) NULL,
  b VARCHAR(255) NULL,
  c VARCHAR(255) NULL,
  d VARCHAR(255) NULL,
  e VARCHAR(255) NULL,
  PRIMARY KEY (mykey)
);

SQL queries

-- name: TestInsert :exec
INSERT INTO dep_names 
  (mykey, a, b, c, d, e)
VALUES 
  (?, ?, ?, ?, ?, ?) as new
ON DUPLICATE KEY UPDATE 
  a = new.a,
  b = new.b,
  c = new.c,
  d = new.d,
  e = new.e;

Configuration

version: 2
sql:
  - engine: "mysql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "sqlc"
        out: "sqlc"

Playground URL

https://play.sqlc.dev/p/99bd4e6529ffaae574dacb08c653ada803cc5c95a4a42e795e4a39cb039a4a47

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Sep 28, 2023
  2. orisano commented on Sep 29, 2023

    @orisano
    Contributor

    The mysql engine relies on the tidb parser.
    Currently it does not work because tidb does not support that syntax.

    pingcap/tidb#29259

  3. added
    upstreamIssue is caused by a dependency
    and removed
    triageNew issues that hasn't been reviewed
    on Sep 29, 2023
  4. Jille commented on Feb 27, 2024

    @Jille
    Contributor
  5. SnoozeThis commented on Feb 27, 2024

    @SnoozeThis

    (https://snoozeth.is/xBlBhXIndU8) I will wait until pingcap/tidb#29259 is closed and then add a comment.

  6. SnoozeThis commented on Mar 1, 2025

    @SnoozeThis

    Resolved.

  7. jessepeterson commented on Aug 28, 2025

    @jessepeterson
    Author

    This was not "resolved" upstream, FYI. The TIDB issue above was merely closed as a duplicate of a newer issue.

  8. paultyng commented on May 12, 2026

    @paultyng

    I think I have a PR for this in marino here: sqlc-dev/marino#33

    cc @kyleconroy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    📚 mysqlbugSomething isn't workingupstreamIssue is caused by a dependency

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions