-
Notifications
You must be signed in to change notification settings - Fork 922
Closed
Labels
bugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed
Description
Version
1.23.0
What happened?
when use case
expression in sqlite sql queries:
-- name: UpdateNode :one
UPDATE node
SET name =
CASE
WHEN sqlc.arg(doupdate) THEN sqlc.arg(name)
ELSE name
END
WHERE id = sqlc.arg(id)
RETURNING *;
the generated golang code is not expected (see those sqlc.arg
macros):
const updateNode = `-- name: UpdateNode :one
UPDATE node
SET name =
CASE
WHEN sqlc.arg(doupdate) THEN sqlc.arg(name)
ELSE name
END
WHERE id = ?1
RETURNING id, name
`
if the sql query parameters using ?#
instead:
-- name: UpdateNode :one
UPDATE node
SET name =
CASE
WHEN ?1 THEN ?2
ELSE name
END
WHERE id = ?3
RETURNING *;
then sqlc generate
command exits with error:
❯ sqlc generate
# package sqlx
query.sql:1:1: could not determine data type of parameter $1
main.go:12: running "sqlc": exit status 1
Relevant log output
No response
Database schema
CREATE TABLE IF NOT EXISTS node (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE COLLATE NOCASE
);
SQL queries
-- name: UpdateNode :one
UPDATE node
SET name =
CASE
WHEN sqlc.arg(doupdate) THEN sqlc.arg(name)
ELSE name
END
WHERE id = sqlc.arg(id)
RETURNING *;
Configuration
{
"version": "2",
"sql": [{
"schema": "schema.sql",
"queries": "query.sql",
"engine": "sqlite",
"gen": {
"go": {
"out": "db"
}
}
}]
}
Playground URL
https://play.sqlc.dev/p/ea1bdcffa39020ef642974baf6a26e1f07186f83165c5558908630fabd04ce6a
What operating system are you using?
Linux
What database engines are you using?
SQLite
What type of code are you generating?
Go
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingtriageNew issues that hasn't been reviewedNew issues that hasn't been reviewed