sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.54k stars 809 forks source link

sqlc.slice incompatible with prepared queries #3659

Open eloff opened 1 month ago

eloff commented 1 month ago

Version

1.27.0

What happened?

I understand that slice can't be used with prepared queries, but it seems that if you enable prepared queries with emit_prepared_queries: true it will try to prepare queries that use sqlc.slice anyway, and this will obviously fail. Ideally any queries that can be prepared, should still be prepared, and those that can't, won't be. I was a bit surprised to find that doesn't seem to be the behavior, and that if you use sqlc.slice the only option today seems to be disabling emit_prepared_queries.

Relevant log output

error preparing query DeleteTasks: near "?": syntax error

Database schema

No response

SQL queries

-- name: DeleteTasks :many
-- DeleteTasks deletes all tasks with the ids and returns them.
delete
from tasks
where id in sqlc.slice(ids) returning *;

Configuration

No response

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

rishi-kulkarni commented 1 month ago

I'd add onto this that it'd be nice to selectively prepare queries in general. When beginning a batch insert transaction, for example, I only want to prepare a subset of my queries on the Tx.