Skip to content

Duplicate query names produces cryptic Go error #220

@CaptainCharlieGreen

Description

@CaptainCharlieGreen

If you accidentally create two queries with the same name the generated go code has an error about an 'ambiguous selector"

-- name: GetReportByID :one
SELECT * FROM abuse_report
WHERE id = $1;

-- name: GetReportByID :one
SELECT * FROM abuse_report
WHERE id = $1;

Produces in db.go:

	if q.getReportByIDStmt, err = db.PrepareContext(ctx, getReportByID); err != nil {
		return nil, fmt.Errorf("error preparing query GetReportByID: %w", err)
	}
	if q.getReportByIDStmt, err = db.PrepareContext(ctx, getReportByID); err != nil {
		return nil, fmt.Errorf("error preparing query GetReportByID: %w", err)
	}

which fails to compile:
"ambiguous selector q.getReportByIDStmt"

My expected behavior is sqlc fails generation with an error indicating there are multiple queries with the same name.

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