Skip to content

NullInt32 - could not determine data type of parameter $1 #281

@Saticmotion

Description

@Saticmotion

I'm trying to run a query with an optional WHERE:

//userid is pgx.NullInt32
//count is int
//offset is int

//if userid.Valid is false this should evaluate to NULL is NULL, and thus not filter on userid 
rows, err := dbPool.Query(`SELECT id, userid, timestamp, downloadsize FROM videos
						WHERE ($1 IS NULL OR userid=$1) 
						LIMIT $2
						OFFSET $3`, userid, count, offset)

Table videos looks like:

id				uuid
userid			integer
timestamp		timestamp without timezone
downloadsize	integer

But this returns the error could not determine data type of parameter $1 (SQLSTATE 42P08). The error occurs both when userid.Valid is true and when false.

What am I doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions