sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
12.28k stars 777 forks source link

Capital letters in table alias causes generation to fail #3262

Open mlucic opened 6 months ago

mlucic commented 6 months ago

Version

1.25.0

What happened?

Trying to generate a query where there is a table alias with capital letters causes the generation to fail with the error column "id" does not exist. Changing the alias to have only lowercase letters fixes the problem. Both are valid for MySQL, so sqlc should not be erroring when there are capital letters in the alias.

Relevant log output

$ sqlc generate
# package sqlc
query.sql:16:5: column "id" does not exist

Database schema

CREATE TABLE `blue` (
  `id` int NOT NULL AUTO_INCREMENT
  PRIMARY KEY (`id`)
);

SQL queries

SELECT
    `A`.`id`
FROM
    blue AS `A`;

Configuration

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

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

mlucic commented 6 months ago

Just found that the same error happens at runtime when using sqlc.embed where the table has a capital letter in it

e.g.

SELECT sqlc.embed(blueTable)
FROM blueTable;