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

Where condition placeholder #363

Open
dennissetiawan opened this issue Jul 14, 2023 · 2 comments
Open

Where condition placeholder #363

dennissetiawan opened this issue Jul 14, 2023 · 2 comments

Comments

@dennissetiawan
Copy link

dennissetiawan commented Jul 14, 2023

I noticed something weird why can't we use ? in column name?
sql, args, err := sb.Select("test").Where("y = ?", 2).ToSql() OK
but
sql, args, err := sb.Select("test").Where("? = ?","y", 2).ToSql()
error

this also happens in sq.Expr

@crjm
Copy link

crjm commented Dec 5, 2023

Hey!
Encountered the same issue when passing two arguments to SelectBuilder.Where.

For example:

testQuery := sq.Select("test").
	From("test").
	Where("? = ?", 1, 2)

query, args, err := testQuery.ToSql()
fmt.Printf("query: %s\n", query)
fmt.Printf("args: %v\n", args)
query: SELECT test FROM test WHERE ? = ?
args: [1 2]

This is the error I get.

*errors.errorString have no arg for param ? at position 1

This doesn't happen with SelectBuilder.Having for example.

@crjm
Copy link

crjm commented Dec 5, 2023

Turns out I was not passing args as a slice in the follow-up implementation. The issue was not related to this library.
My bad!

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