-
Notifications
You must be signed in to change notification settings - Fork 937
Open
Labels
Description
Version
1.30.0
What happened?
The generated code below is wrong. There are three question marks in the sql query, but we only pass two arguments for the query in the ExecContext line, so the sql query fails.
Arguably the query should be using excluded.* syntax, but it would have been nice for sqlc to fail in that case.
const insertXForEmailUser = `-- name: InsertXForEmailUser :exec
INSERT INTO x (user_id, x)
VALUES ((SELECT user_id FROM users WHERE email = ?), ?)
ON CONFLICT(x)
DO UPDATE SET user_id = (SELECT user_id FROM users WHERE email = ?)
`
type InsertXForEmailUserParams struct {
Email interface{}
X interface{}
}
func (q *Queries) InsertXForEmailUser(ctx context.Context, arg InsertXForEmailUserParams) error {
_, err := q.db.ExecContext(ctx, insertXForEmailUser, arg.Email, arg.X)
return err
}
Relevant log output
Database schema
CREATE TABLE x (user_id string, x string);
2
CREATE TABLE users (user_id string, email string);
SQL queries
-- name: InsertXForEmailUser :exec
INSERT INTO x (user_id, x)
VALUES ((SELECT user_id FROM users WHERE email = ?), ?)
ON CONFLICT(x)
DO UPDATE SET user_id = (SELECT user_id FROM users WHERE email = ?);
Configuration
{
"version": "2",
"sql": [{
"schema": "schema.sql",
"queries": "query.sql",
"engine": "sqlite",
"gen": {
"go": {
"out": "db"
}
}
}]
}
Playground URL
https://play.sqlc.dev/p/b5c3c6e7c95b77f6e2a0e9bd7d19956c80b9b6ef43051369823318f1883bd9b2
What operating system are you using?
macOS
What database engines are you using?
SQLite
What type of code are you generating?
Go