A query that contains a slice and a regular parameter generates query code with incorrect placeholder ordinal
jhlgns opened this issue · 1 comments
Version
1.27.0
What happened?
Hello, I was just pulling out my non-existent hairs about why the filtering of my blog articles produced article lists that made no sense.
I have this query:
-- name: ListArticles :many
select *
from articles
where
(category in (sqlc.slice(categories))) and
(sqlc.arg(include_drafts) = 1 or is_visible = 1)
order by created_at desc;
Which generates this query code:
const listArticles = `-- name: ListArticles :many
select id, created_at, last_edited_at, is_visible, title, category, content, content_type
from articles
where
(category in (/*SLICE:categories*/?)) and
(?2 = 1 or is_visible = 1)
order by created_at desc
`
However, the ?2
here means that not the wanted IncludeDrafts
parameter of the paramter struct is inserted, but the second element in the parameter array, which is the second element of the categories
array.
When I manually replace the ?2
with ?
, it works as expected.
One solution could be either to not emit placeholder ordinals or to enumerate the slice placeholders as well.
Relevant log output
No response
Database schema
No response
SQL queries
No response
Configuration
No response
Playground URL
No response
What operating system are you using?
No response
What database engines are you using?
SQLite
What type of code are you generating?
Go
Same problem for me. I have to move the slice parameter to the last position as a workaround.