-
Notifications
You must be signed in to change notification settings - Fork 470
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
Multiple tuple where clause #104
Comments
Squirrel does not support tuples. You could rewrite the query with Or and Eq: sq.Or{sq.Eq{"name": "Alex", "age": 10}, sq.Eq{"name": "Douglas", "age": 40}} If you have a fixed number of tuples in your IN clause, you could also write it with Expr: Expr("((name, age)) IN ((?, ?), (?, ?))", "Alex", 10, "Douglas", 40) (examples untested) |
Closing because @lann's comment is sufficient to solve my issue
|
If you need dynamic list of conditions sq.Or{} is an array. May be it will save your time :) some := sq.Or{}
for _, data := range dataList {
some = append(some, sq.Eq{"key1": data.Value1, "key2": data.Value2})
}
squirrel.Select(*).From("table").Where(some)
// SELECT * FROM table WHERE (key1 = $1 AND key2 = $2 OR key1 = $3 AND key2 = $4) |
Thank you, an example from my code pkConditions := sq.Or{}
for pkIdx := 0; pkIdx < len(primaryKeys); pkIdx++ {
pk := primaryKeys[pkIdx]
pkConditions = append(pkConditions, sq.And{
sq.Eq{"c.location_uid": pk.LocationUID},
sq.Eq{"c.shipment_provider_uid": pk.ShipmentProviderUID},
sq.Eq{"c.shipment_method_uid": pk.ShipmentMethodUID},
})
}
q = q.Where(pkConditions) |
I'm trying to recreate this query with squirrel:
The closest I can come up with is this and it's wrong:
The text was updated successfully, but these errors were encountered: