Skip to content

golang: emit one argument for a named parameter used more than once - #4651

Open
tlq5l wants to merge 1 commit into
sqlc-dev:mainfrom
tlq5l:fix/repeated-narg-args
Open

tlq5l wants to merge 1 commit into
sqlc-dev:mainfrom
tlq5l:fix/repeated-narg-args

Conversation

@tlq5l

@tlq5l tlq5l commented Oct 21, 2026

Copy link
Copy Markdown

Fixes #4191

With query_parameter_limit above the number of parameters, the Go codegen lists each parameter as a method argument. A named parameter used twice (sqlc.narg(name) in name = ? OR ? IS NULL) is two parameters on MySQL, so it produced ListUsers(ctx, name sql.NullString, name sql.NullString) and the package did not compile.

The struct form already treats such parameters as one field (columnsToStruct gives them the same name and UniqueFields declares it once). QueryValue.Pairs built the inline argument list from all fields instead. It now uses UniqueFields, so the argument is declared once and still bound to both placeholders.

Added an end-to-end case, query_parameter_limit_repeated_narg, that repeats sqlc.narg(name) alongside another parameter.

Ran live: sqlc generate && go vet ./db on the issue's schema and query with query_parameter_limit: 5 -> before: name redeclared in this block; after: generates ListUsers(ctx, name sql.NullString, minAge int32) calling QueryContext(..., name, name, minAge) and vet passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional WHERE parameters via $1 IS NULL OR - redeclared in this block - query_parameter_limit

1 participant