GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Optional WHERE parameters via $1 IS NULL OR - redeclared in this block - query_parameter_limit · Issue #4191 · sqlc-dev/sqlc

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

New issue
Copy link
New issue
Copy link
Open
#4651
Open
Optional WHERE parameters via $1 IS NULL OR - redeclared in this block - query_parameter_limit#4191
#4651
Copy link
Labels
📚 mysql💻 darwin🔧 golangbugSomething isn't workingSomething isn't working

Description

@sergeishilkocardmarket
sergeishilkocardmarket
opened on Nov 21, 2025
Issue body actions

Version

1.30.0

What happened?

Fail to generate go gode when using named argument >1 for optional SELECT WHERE query case
see #200

suggested solution does not work in 1.30.0 in golang

Image

would generate go compile error name redeclared in this block

Relevant log output

Go auto-generated code

// ListUsers
//
//	SELECT name
//	FROM users
//	WHERE
//	 (name = ? OR ? IS NULL)
func (q *Queries) ListUsers(ctx context.Context, name *string, name *string) ([]string, error) {

go build

# query_parameter_limit = 4 (important) will generate  (ISSUE) duplicate func args
# query_parameter_limit = 1 will generate struct, no duplicate  (NO ISSUE)

sqlc/maindb/users.sql.go:25:64: name redeclared in this block
sqlc/maindb/users.sql.go:25:50: other declaration of name

Database schema

CREATE TABLE users (name TEXT NOT NULL);

SQL queries

-- name: ListUsers :many
SELECT *
FROM users
WHERE
 (name = sqlc.narg('name') OR sqlc.narg('name') IS NULL)


Configuration

version: "2"
sql:
  - engine: "mysql"
    queries: "./db/maindb/queries/"
    schema: "./db/maindb/migrations/"
    gen:
      go:
        package: "maindb"
        out: "internal/infra/sqlc/maindb"
        sql_package: "database/sql"
        sql_driver: "github.com/go-sql-driver/mysql"
        emit_interface: true
        emit_json_tags: true
        json_tags_case_style: "camel"
        emit_prepared_queries: true
        emit_exact_table_names: true
        emit_empty_slices: true
        emit_result_struct_pointers: true
        emit_params_struct_pointers: true
        query_parameter_limit: 4
        emit_db_tags: true
        emit_enum_valid_method: true
        emit_all_enum_values: true
        emit_sql_as_comment: true

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Activity

  1. sergeishilkocardmarket
    added
    bugSomething isn't workingSomething isn't working
    on Nov 21, 2025
  2. dosubot
    added
    📚 mysql
    💻 darwin
    🔧 golang
    on Nov 21, 2025
  3. sergeishilkocardmarket commented on Nov 21, 2025

    @sergeishilkocardmarket
    sergeishilkocardmarket
    on Nov 21, 2025
    Author
    More actions

    changing query_parameter_limit: 1 emits a proper struct, but when using parameters there is an issue.

    Is there chance query_parameter_limit can be overriden on per-query basis?

  4. sergeishilkocardmarket
    changed the title [-]Optional WHERE parameters via $1 IS NULL OR - redeclared in this block[/-] [+]Optional WHERE parameters via $1 IS NULL OR - redeclared in this block - query_parameter_limit[/+] on Nov 21, 2025
  5. sergeishilkocardmarket commented on Nov 21, 2025

    @sergeishilkocardmarket
    sergeishilkocardmarket
    on Nov 21, 2025
    Author
    More actions

    As a solution to this,
    ideally an option to override query_parameter_limit per query,
    or option to always use struct argument per query

    -- name: ListUsers :many
    -- query_parameter_limit: 0
    -- argsType: struct
    SELECT *
    FROM users
    WHERE
     (name = sqlc.narg('name') OR sqlc.narg('name') IS NULL)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    📚 mysql💻 darwin🔧 golangbugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.