Skip to content

CASE with Named Params Ignored #1195

Closed
Closed
@jamisonhyatt

Description

@jamisonhyatt

Version

1.10.0

What happened?

I was playing around, writing code to work around #1155 with a CASE statement in mysql, and the generated code completely ignores the named parameters.

edit: Ignore the validity of the schema/sql - I'm aware it janky - was just copy and pasting. 😂

This could be the same failure to parse as #1194, but I wasn't sure and it felt better raised as 2 separate issues.

Postgres working example

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGINT PRIMARY KEY,
  username TEXT NULL,
  email TEXT NULL,
  name TEXT  NOT NULL,
  bio  TEXT,
  UNIQUE KEY idx_username (username),
  UNIQUE KEY ids_email (email)
);

SQL queries

-- name: ListAuthors :one
SELECT * FROM authors
WHERE email = CASE WHEN sqlc.arg(email) = '' then NULL else sqlc.arg(email) END
OR username = CASE WHEN sqlc.arg(username) = '' then NULL else sqlc.arg(username) END 
LIMIT 1;

Configuration

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

Playground URL

https://play.sqlc.dev/p/775c20fa89d28dc02643c0b8678d48a08bd58de32d24ae9ada73ffe9f157e5ab

What operating system are you using?

No response

What database engines are you using?

MySQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions