Skip to content
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

sqlc.slice() fails with 'column does not exist' error when used with subquery-computed column #3720

Open
kawatakutaku opened this issue Nov 23, 2024 · 0 comments
Labels
📚 mysql bug Something isn't working

Comments

@kawatakutaku
Copy link

kawatakutaku commented Nov 23, 2024

Version

1.27.0

What happened?

When using sqlc.slice() with a column computed in a subquery, sqlc generate fails with a "column does not exist" error. This occurs even though the column is correctly defined and aliased in the subquery.

Relevant log output

query.sql:18:3: 396: column "full_name" does not exist

Database schema

CREATE TABLE customers (
  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,  
  first_name varchar(255) not null,
  last_name varchar(255) not null
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4;

SQL queries

-- name: GetFullNames :many
SELECT
 full_name
FROM
  (
    SELECT
  	 concat(first_name, ' ', last_name) as full_name
    FROM
      customers
  ) subquery
WHERE
  full_name IN (sqlc.slice ("full_names"));

Configuration

{
  "version": "2",
  "sql": [
    {
      "schema": "query.sql",
      "queries": "query.sql",
      "engine": "mysql",
      "gen": {
        "go": {
          "package": "db",
          "out": "db"
        }
      }
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/043ded77492cec27dbba4e964774d08836ad76227a585856ae284f13f9046f24

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@kawatakutaku kawatakutaku added the bug Something isn't working label Nov 23, 2024
@dosubot dosubot bot added the 📚 mysql label Nov 23, 2024
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
Projects
None yet
Development

No branches or pull requests

1 participant