Skip to content

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

Closed
@zhengyangfeng00

Description

@zhengyangfeng00

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions