sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Code for pgx/v4 doesn't compile with same named input and output param

Open Jille opened this issue 2 years ago • 1 comments

Version

1.12.0

What happened?

I have a query that takes id as its only input, and also returns id as its only output.

That causes the function arg and a variable to be called id, thus failing compilation.

Fascinating is that this only breaks with pgx/v4, not with database/sql. The latter seems to reuse the variable and make it work.

Relevant log output

gendb/queries.sql.go:16:6: id redeclared in this block
  gendb/queries.sql.go:14:68: previous declaration

Database schema

No response

SQL queries

INSERT INTO authors (name) SELECT name FROM authors a WHERE a.id = $1 RETURNING id;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/d7186cbc2c17613b4ab6fc927330fb20d7848c5c7eb75e975e8d3e55a53a279a

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Jille avatar Mar 16 '22 09:03 Jille

Similar bug to https://github.com/kyleconroy/sqlc/issues/1453

kyleconroy avatar Aug 29 '22 02:08 kyleconroy

Seems to fixed by #1298

zaneli avatar Feb 04 '23 16:02 zaneli

Seems to fixed by #1298

Just tried - but the issue still occurs in sqlc v1.16.0.

sgielen avatar Feb 09 '23 15:02 sgielen

@sgielen Oh, #1298 seems to have been fixed only for the stdlib template. 🙇 I try to fix for the pgx template. #2058

zaneli avatar Feb 10 '23 03:02 zaneli