sqlc-dev / sqlc

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

Using function on column in WHERE clause does not generate parameter #3463

Open mlucic opened 3 months ago

mlucic commented 3 months ago

Version

1.26.0

What happened?

This issue appears to be the same found in #103

Given a table with string column a and number column b, the following query will not generate a parameter for column a.

Removing the LOWER() invocation results in the parameter being created

Relevant log output

unknown field A in struct literal of type sqlc.GetThingsParams

Database schema

CREATE TABLE `myTable` (
  `a` varchar(255) NOT NULL,
  `b` int NOT NULL,
  PRIMARY KEY (`a`,`b`)
);

SQL queries

-- name: GetThings :many
SELECT
  a,
  count(b) as cnt
FROM myTable
WHERE LOWER(a) IN (sqlc.slice('a'))
  AND b IN (sqlc.slice('b'))
GROUP BY a
ORDER BY cnt DESC
LIMIT ?;

Configuration

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

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go