Skip to content

Function with named parameter produces invalid Golang struct and SQL query #576

@ryanwmoore

Description

@ryanwmoore

Using sqlc 1.4.0 + Postgres 11.8. This is a reproduction of the same behavior I saw in a real/non-trivial query.

Given:

-- name: Demo :one
SELECT uuid_generate_v5('7c4597a0-8cfa-4c19-8da0-b8474a36440d', @param)::uuid as col1
;

Produces the following:

const demo = `-- name: Demo :one
SELECT uuid_generate_v5('7c4597a0-8cfa-4c19-8da0-b8474a36440d', $1)::uuid as col1
`

type DemoParams struct {
	Param interface{}
	Param interface{}
}

// SELECT @other as col2, uuid_generate_v5('7c4597a0-8cfa-4c19-8da0-b8474a36440d', @param::varchar)::uuid as col1
func (q *Queries) Demo(ctx context.Context, arg DemoParams) (uuid.UUID, error) {
	row := q.db.QueryRowContext(ctx, demo, arg.Param, arg.Param)
...

The problems that I see are:

  1. The Param field is duplicated
  2. The generated string query has only 1 parameter, but QueryContext is called with 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions