squirrel
squirrel copied to clipboard
error when using sqlx
query := sq.sq.Select(`COALESCE(MAX(ID),0)`).From(`channel`)
if len(name) != 0 {
query = query.Where(sq.Eq{"name":name})
}
if true {
query = query.Where(sq.Eq{"active":active})
}
// result
// sql = SELECT COALESCE(MAX(ID),0) FROM channel WHERE name = ?
// args = []interface{} & 0 = xxxx
sql,args,err := query.ToSql()
if err != nil {
return err
}
err = sqlx.GetContext(ctx,&data,sql,args...)
if err != nil{
// output
// pq: syntax error at end of input
}
I checked the sql is correct, does anyone know why this is?
What sql engine are you using? ? syntax won't work on PostGreSQL.
It's also suspicious that I don't see a WHERE active = ? in the sql you're showing here.
How did you check the sql is correct? Did you evaluate it directly against your database?