sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Named parameters not working in subquery inside MySQL IN clause

Open bryandantas opened this issue 3 years ago • 1 comments

Version

1.12.0

What happened?

On use subquery inside MySQL IN or NOT IN clauses, parameters not working. When I use sqlc.arg(), generated code not recognizes parameter. When I use ? character, the param code not is generated.

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGINT PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

CREATE TABLE posts (
  id   BIGINT PRIMARY KEY,
  title text      NOT NULL,
  author_id BIGINT
);

SQL queries

-- name: GetPost :one
SELECT * FROM posts WHERE author_id NOT IN (SELECT id FROM authors WHERE name LIKE sql.arg(author_name))

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

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

What operating system are you using?

No response

What database engines are you using?

MySQL

What type of code are you generating?

Go

bryandantas avatar Feb 17 '22 18:02 bryandantas

I've reproduced this in the latest version here. ? placeholders work fine; it's just the sqlc.arg() syntax.

kyleconroy avatar Aug 29 '22 02:08 kyleconroy

i also can reproduce this issue with 1.18.

ecornelisse avatar May 27 '23 19:05 ecornelisse

It seems to work correctly in 1.20. https://play.sqlc.dev/p/11240140f47c8020ec97bedca3d8200b4a22c9557ed9f4acf1e0d5afcc116626

orisano avatar Aug 05 '23 05:08 orisano