Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when using sqlx #341

Open
keeprockin2019 opened this issue Nov 14, 2022 · 2 comments
Open

error when using sqlx #341

keeprockin2019 opened this issue Nov 14, 2022 · 2 comments

Comments

@keeprockin2019
Copy link

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
}
@keeprockin2019
Copy link
Author

I checked the sql is correct, does anyone know why this is?

@jlautman
Copy link

jlautman commented Dec 9, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants