Skip to content

Missing binds in ORDER BY #1194

Closed
Closed
@jamisonhyatt

Description

@jamisonhyatt

Version

1.10.0

What happened?

👋 Experimenting with sqlc and conditional order by's aren't generating the code for mysql as I'd expect. Didn't see any matching issues - hopefully I didn't miss one.

As you can see by the example below, the mysql generated code skips the sqlc.arg(sort_column) bind.

As an alternate example, here's postgres working as expected

Relevant log output

No response

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   BIGINT PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: ListAuthors :many
SELECT * FROM authors
WHERE id > sqlc.arg(min_id) 
ORDER BY CASE WHEN sqlc.arg(sort_column) = 'name' THEN name END;

Configuration

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

Playground URL

https://play.sqlc.dev/p/4d6a51438a52ec0067279884c6327f14e1c2e50d3057591178c44e438f926385

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