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 with raw sql string and slice arg #383

Open
m15h4nya opened this issue Oct 22, 2024 · 2 comments
Open

Where with raw sql string and slice arg #383

m15h4nya opened this issue Oct 22, 2024 · 2 comments

Comments

@m15h4nya
Copy link

m15h4nya commented Oct 22, 2024

Given:

query := sq.Select("something FROM somewhere").Where("id NOT IN ?", []int{1, 2, 3})

Expected:

SELECT something FROM somewhere WHERE id NOT IN (1, 2, 3);

Actual:

SELECT something FROM somewhere WHERE id NOT IN '[1 2 3]';

Trying to actually execute query returns error (SQLSTATE 42601) saying there is syntax error near ? (or $1 if using dollar placeholders)

go play: https://go.dev/play/p/79B21fBnUgJ

@torbenj
Copy link

torbenj commented Nov 4, 2024

Using sq.NotEq might solve this issue:

query := sq.Select("something FROM somewhere").Where(sq.NotEq{"id": []int{1, 2, 3}})

@m15h4nya
Copy link
Author

m15h4nya commented Nov 4, 2024

@torbenj
Yeah, it works. But actually it's not solution but rather a work around. Since lib supports text+arg format it should also handle such case correctly i guess. I'll try to contribute some fixes when have some free time (wanted before, just forgot tho)

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