Skip to content

MySQL queries that use the same parameter in two places #777

Closed
@alecbz

Description

@alecbz

A MySQL query like:

SELECT * FROM things WHERE foo = sqlc.arg(foo) OR old_foo = sqlc.arg(foo)

gets compiled into:

const query = `SELECT * FROM things WHERE foo = ? OR old_foo = ?`

func (q *Queries) GetThingByFoo(ctx context.Context, foo string) (Thing, error) {
  row := q.db.QueryRowContext(ctx, query, foo)
  ...
}

which causes MySQL to complain because only one argument is supplied when it was expecting two.


It seems like we should at least error out during code generation in this case, but even better would be to do:

row := q.db.QueryRowContext(ctx, query, foo, foo)

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