sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Duplication of fields when generating for pgx/v5

Open AlexanderMint opened this issue 1 year ago • 1 comments

Version

1.24.0

What happened?

Multiple fields with the same name are generated

It will work correctly if you use enumerations ($1, $2, etc.) or sqlc.arg(number)

Relevant log output

type UpdateParams struct {
	Number int32
	ID     int32
	Number int32
}

Database schema

CREATE TABLE public.demo (
    id INT PRIMARY KEY,
    number integer NOT NULL
);

SQL queries

-- name: Update :one
UPDATE demo
SET number = @number
WHERE id = @id
	AND number = @number - 1
RETURNING true AS updated;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db",
        "sql_package": "pgx/v5"
      }
    }
  }]
}

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

AlexanderMint avatar Dec 26 '23 01:12 AlexanderMint

I looked into it, if you enclose the named parameter in () then it works. i.e.

UPDATE demo
SET number = @number
WHERE id = @id
	AND number = (@number) - 1
RETURNING true AS updated;

it is parsing the name as -name

abdullah2993 avatar Jan 13 '24 12:01 abdullah2993