Luis Serra
Luis Serra

Reputation: 131

Bindvars in golangs sqlx.DB.Select() statement requires 0 parameters

I'm using SQLX and PQ to query an SQL database with PostGress. I'm using the function Select from SQLX with bindvars but PQ panics with

pq: got 1 parameters but the statement requires 0.

 query = `
    SELECT 
        count(*) AS count 
    FROM 
        ledger 
    WHERE 
        enterprise_id=($1)
 `
 var stat singleStat

 err = db.Select(&stat, query, enterpriseID)

Upvotes: 5

Views: 1475

Answers (1)

Luis Serra
Luis Serra

Reputation: 131

If anyone gets to here, I found out the answer by digging a bit on the pq source code. To use prepared parameters with Crate, it requires driver to send the parameters as binary before preparing the statement; answering with the types of the parameters.

To accomplish this, add 'binary_parameters=yes' to your connection string. Like:

"user=crate dbname=test binary_parameters=yes"

Upvotes: 1

Related Questions