Skip to content

mysql 8 insert on duplicate syntax error #3977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qingmo opened this issue May 30, 2025 · 0 comments
Open

mysql 8 insert on duplicate syntax error #3977

qingmo opened this issue May 30, 2025 · 0 comments
Labels
📚 mysql bug Something isn't working 🔧 golang

Comments

@qingmo
Copy link

qingmo commented May 30, 2025

Version

1.28.0

What happened?

-- name: UpcreateUserAccountBalance :execresult
INSERT INTO user_balance (
    
    user_id,
    amount,
    create_time,
    update_time
) VALUES (
    
    ?,
    ?,
    now(),
    now()
) 
as new_item 
ON DUPLICATE KEY UPDATE
amount = new_item.amount,
update_time = now();

syntax error near "as new_item "

Relevant log output

syntax error near "as new_item "

Database schema

CREATE TABLE `user_balance` (
  `id` bigint NOT NULL AUTO_INCREMENT ,
  `user_id` varchar(64) NOT NULL DEFAULT '' ,
  `amount` decimal(65,30) NOT NULL DEFAULT '0.000000000000000000000000000000',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;

SQL queries

-- name: UpcreateUserAccountBalance :execresult
INSERT INTO user_balance (
    
    user_id,
    amount,
    create_time,
    update_time
) VALUES (
    
    ?,
    ?,
    now(),
    now()
) 
as new_item 
ON DUPLICATE KEY UPDATE
amount = new_item.amount,
update_time = now();

Configuration

version: "2"
plugins:
sql:
  - engine: "mysql"
    queries: "./sql/queries/"
    schema: "./sql/schema/"
    gen:
      go:
        package: "repository"
        out: "internal/repository"
        emit_db_tags: true
        overrides:
          - db_type: "decimal"
            go_type: "float64"

Playground URL

https://play.sqlc.dev/p/e4180de8a61bce51224656a0464de8b9c7be9ef46c2315b5bc26990a76ef1e13

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@qingmo qingmo added the bug Something isn't working label May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mysql bug Something isn't working 🔧 golang
Projects
None yet
Development

No branches or pull requests

1 participant