Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

go

sqlx

pq

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)
like image 460
Luis Serra Avatar asked Nov 07 '22 10:11

Luis Serra


1 Answers

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"

like image 82
Luis Serra Avatar answered Nov 22 '22 13:11

Luis Serra