sqlc-dev / sqlc

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

pg: `WHERE ... id = ANY($1::TYPE[])` generates query with wrong returning named parameter #2631

Closed arham09 closed 1 year ago

arham09 commented 1 year ago

Version

1.18.0

What happened?

When generating an update query using a WHERE ... IN id = ANY($1::TYPE[]) statement, I expected to get a function that have a named parameter based on the column in the query which is id, instead of getting id the result from generated function is Column1, see playground link

Current workarround, I guess I can wrap the generated function manually, but will be better if this fixed, considered if this one is a legit bug, but if not please tell me where I went wrong

Thank you 🙇

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: UpdateAuthor :exec
UPDATE authors
SET name = $2
WHERE id = ANY($1::BIGSERIAL[]);

Configuration

No response

Playground URL

https://play.sqlc.dev/p/693bb4a6f7a05286b91f04bee63aae12cadbfaf5eab82e459b8886d0b2d8736f

What operating system are you using?

Linux, macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

orisano commented 1 year ago

Please use named parameter. https://play.sqlc.dev/p/9826b0fe13db496592fc778302961391e31a9562a7b08a08e9508a746a8a54cd

arham09 commented 1 year ago

Thank you @orisano , I'll close the issue