Skip to content

SQLC Generated Go Code Throws Scan Error for Non-Existent user_id #2677

@qcrao

Description

@qcrao

Version

1.20.0

What happened?

I am using SQLC to generate Go code for my SQL queries. I have defined the following SQL statement:

-- name: GetUserDepositCountBetween :one
SELECT user_id, COUNT(*) AS deposit_count FROM transaction WHERE user_id = ? and type = 'deposit' and created_at >= sqlc.arg(start) AND created_at < sqlc.arg(end);

When executing the generated Go code, I encounter an error if the user_id is not found in the database. The error message is:

"error":"sql: Scan error on column index 0, name \"user_id\": converting NULL to int64 is unsupported"

This makes it difficult for me to distinguish between a timeout error and a "record not found" error.

Relevant log output

error message: "error":"sql: Scan error on column index 0, name \"user_id\": converting NULL to int64 is unsupported"

Database schema

No response

SQL queries

-- name: GetUserDepositCountBetween :one
SELECT user_id, COUNT(*) AS deposit_count FROM transaction WHERE user_id = ? and type = 'deposit' and created_at >= sqlc.arg(start) AND created_at < sqlc.arg(end);

Configuration

No response

Playground URL

No response

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 workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions