Skip to content

When using "pgx" driver, sqlx interprets Postgres integer[] array as string and fails to Scan() #193

Closed
@ARolek

Description

@ARolek

When using the pgx driver the following query where ids is a Postgres array integer[] fails with the error: sql: Scan error on column index 0: unsupported driver -> Scan pair: string -> *[]int32

conn, err = sqlx.Connect("pgx", ...)
if err != nil {
    log.Fatal(err)
}

query := fmt.Sprintf(`
    SELECT 
        ids
    FROM 
        %v
    WHERE
        id=1
`, IdsTable)

var ids []int32
err = conn.QueryRow(query).Scan(&ids)

If I use the pgx driver directly, the array is decoded into a Go slice fine. Here's the code:

conn, err := pgx.Connect(config)
if err != nil {
    log.Fatal(err)
}

query := fmt.Sprintf(`
    SELECT 
        ids
    FROM 
        %v
    WHERE
        id=1
`, IdsTable)

var ids []int32
err = conn.QueryRow(query).Scan(&ids)

Any idea why using sqlx is interpreting the Postgres array integer[] as a string?

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