Closed
Description
What happened?
Hello, I'm trying to generate Go Code from SQL Query using ANY method. When I run sqlc generate
, variable with array method gets unexpected name.
Actual result: Variable with []int type gets dollar_1
name
Expected result: Variable gets IDs
name
Note: variable might get Column + Number
name (e.g. Column4) when sql query contains several ANY methods in it.
Database schema
CREATE TABLE pilots (
id BIGSERIAL PRIMARY KEY
);
SQL queries
-- name: ListPilotsByIDs :many
SELECT * FROM pilots
WHERE id = ANY($1::int[]);
Configuration
Playground URL
https://play.sqlc.dev/p/455e276514a8ecf33f4d86175da22a6965058d86d08a9e127c59e3a3a9acbad4
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
kyleconroy commentedon Feb 11, 2020
Agreed that this is a bug. In the meantime, you can use named parameters to get the correct parameter name:
Or using the
@
shortcut:MinSomai commentedon Apr 7, 2021
Below doesn't work. any solution to this? (ANSWERED)
error
Update:
seems I can use sqlc.arg with limit but I cannot name it limit
like this
Update:
this works.
theenoahmason commentedon Dec 24, 2021
@kyleconroy How can I accomplish the above example in MySQL?
sqlc.arg('ids')::int[]
results in a syntax error.xeoncross commentedon Feb 12, 2022
Looks like sqlc needs to support passing slices to MySQL queries #695 first
kyleconroy commentedon Sep 22, 2023
This can be accomplished in MySQL and SQLite using sqlc.slice.
As for the parameter name, sqlc.arg Anand named parameters solve this issue nicely.