Skip to content

Error generating code for mysql table with "-" in the table name #1845

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

Closed
zhengyangfeng00 opened this issue Sep 14, 2022 · 1 comment
Closed

Comments

@zhengyangfeng00
Copy link
Contributor

Version

1.15.0

What happened?

Running sqlc to generate go code results in an error: error generating code: source error: 22:9: expected type, found '-' (and 10 more errors)

I believe the reason is that the table name contains "-" and sqlc tries to generate the struct with "-" in it, which is an illegal golang struct name.

Example ddl:

CREATE TABLE IF NOT EXISTS `x-info` (
  `date` DATE NULL DEFAULT NULL,
  `meta` VARCHAR(50) NULL DEFAULT NULL,
  `count` INT(11) NULL DEFAULT NULL)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;

Relevant log output

error generating code: source error: 22:9: expected type, found '-' (and 10 more errors)

Database schema

CREATE TABLE IF NOT EXISTS `x-info` (
  `date` DATE NULL DEFAULT NULL,
  `meta` VARCHAR(50) NULL DEFAULT NULL,
  `count` INT(11) NULL DEFAULT NULL)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4;

SQL queries

-- name: Query :many
SELECT * FROM `x-info`
WHERE meta = ?
;

Configuration

- path: "go/gen/sqlc/xmetricssqlc"
    name: "xmetricssqlc"
    engine: "mysql"
    schema: "ddl.sql"
    queries: "queries.sql"

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@zhengyangfeng00 zhengyangfeng00 added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 14, 2022
@kyleconroy kyleconroy added 📚 mysql 🔧 golang 💻 darwin and removed triage New issues that hasn't been reviewed labels Nov 9, 2022
@kyleconroy
Copy link
Collaborator

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

No branches or pull requests

2 participants