Skip to content

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

Open
@khawa-angx

Description

@khawa-angx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions