sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

sqlc.slice incompatible with prepared queries

Open eloff opened this issue 1 year ago • 1 comments

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

eloff avatar Oct 17 '24 16:10 eloff

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.

rishi-kulkarni avatar Oct 20 '24 14:10 rishi-kulkarni