Skip to content

sqlc generates separate params for same arg #4376

@andylin-0

Description

@andylin-0

Version

1.30.0

What happened?

Query:

-- name: SearchAuthorsFullText :many
SELECT * FROM authors
WHERE MATCH(name) AGAINST(sqlc.arg(search_term))
ORDER BY name = sqlc.arg(search_term) DESC,
MATCH(name) AGAINST(sqlc.arg(search_term)) DESC
LIMIT ?;

generates

type SearchAuthorsFullTextParams struct {
	SearchTerm     string `json:"searchTerm"`
	SearchTerm_3   string `json:"searchTerm3"`
	Limit          int32  `json:"limit"`
}

The playground link does not show this behavior (actually shows a different bug), most likely because you can't use version past 1.25

Relevant log output

Database schema

CREATE TABLE authors (
  id   int  NOT NULL AUTO_INCREMENT,
  name text      NOT NULL,
  bio  text,
  PRIMARY KEY(`id`),
  FULLTEXT KEY `idx_fulltext` (`name`)
);

SQL queries

-- name: SearchAuthorsFullText :many
SELECT * FROM authors
WHERE MATCH(name) AGAINST(sqlc.arg(search_term))
ORDER BY name = sqlc.arg(search_term) DESC,
MATCH(name) AGAINST(sqlc.arg(search_term)) DESC
LIMIT ?;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "mysql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/2054232c1df35a1d15e7c611771cb04d8dffcb438dd083597dce561f24ad1541

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions