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

Unable to recognize the data type of the specified parameter when compiling named arguments, resulting in a syntax error. #3719

Open
khawa-angx opened this issue Nov 22, 2024 · 1 comment
Labels
📚 mysql bug Something isn't working

Comments

@khawa-angx
Copy link

Version

1.27.0

What happened?

I want to filter query results based on certain parameters when retrieving data, but a syntax error occurs when setting the parameter data types.

Relevant log output

query.sql:9:25: syntax error near "::bool, true, delete_time is null)"

Database schema

create table users
(
    id          varchar(191)         not null primary key,
    nickname    varchar(64)          not null,
    email       varchar(255)         not null,
    create_time timestamp            not null,
    update_time timestamp            not null,
    delete_time timestamp            null,
  
    constraint users_email_key unique (email)
) collate = utf8mb4_unicode_ci;

SQL queries

-- name: FindUser :one
select
    *
from
    users
where
    id = ?
  and
    if(@include_removed::bool, true, delete_time is null)
limit
    1;

Configuration

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

Playground URL

https://play.sqlc.dev/p/65875f3f0e264583c140e1ef7be68cf4e078b623d0f5e948d18bad57cc78410d

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@khawa-angx khawa-angx added the bug Something isn't working label Nov 22, 2024
@dosubot dosubot bot added the 📚 mysql label Nov 22, 2024
@khawa-angx
Copy link
Author

According to the documentation at https://docs.sqlc.dev/en/latest/howto/named_parameters.html#naming-parameters, using CASE WHEN also fails to compile. Could it be that MySQL does not support specifying data types for parameters?

-- name: UpsertUserName :execrows
UPDATE users
SET
    nickname = CASE WHEN sqlc.arg(set_name)::bool THEN sqlc.arg(name)::text ELSE nickname END
WHERE
    id = ?;

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