-
Notifications
You must be signed in to change notification settings - Fork 44
fix: handle in/notin operators in token search filters #1656
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
Open
rohilsurana
wants to merge
3
commits into
main
Choose a base branch
from
token-page-filters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
goqu v9 In with string slice on integer column prepared statement postgres operator does not exist integer = text💡 Result:
Root cause: you’re generating a SQL comparison where Postgres sees an integer column on one side and a text/varchar parameter on the other. In Postgres this triggers “operator does not exist: integer = text” (same pattern as integer vs text/varying errors) because there is no matching operator for those types without an explicit cast.[1][2] In goqu v9, build an IN clause using a slice whose element type matches the integer column type (e.g., []int64). goqu will render
"col" IN (...)with those values.[3] What to do 1) Pass integer-typed slice values - Good:goqu.Ex{"id": []int64{1, 2, 3}}. - Bad:goqu.Ex{"id": []string{"1","2"}}(produces text parameters, leading to integer-vs-text operator errors at execution time).[1][2] 2) If your values are strings, convert them before building the query - Convert[]string->[]int64(e.g., with strconv.ParseInt) and pass the resulting[]int64slice to goqu. 3) If you can’t change the types, cast explicitly in SQL - goqu supports raw SQL fragments viagoqu.L(...), which is commonly used when you need explicit casts.[4] Example (working shape) -goqu.Dialect("postgres").From("test").Where(goqu.Ex{"baz": []int64{1,2,3}})produces("baz" IN (1, 2, 3)), and in prepared mode it uses$1..$Nplaceholders with args of the right integer type.[3] If you paste your exact goqu snippet (how you build the slice and which column you target), I can rewrite it into the correct v9 code for your case.Citations:
Restore a type-safe cast for
in/notinon integeramountfiltersThe current refactor builds
valuesas strings and generatesamount IN ($1, $2)-style comparisons without casting, which in Postgres commonly fails withoperator does not exist: integer = textwhen the column is integer and the bound parameters are text. This aligns with whyaddSearchcasts columns (includingamount) toTEXT.🛠️ Proposed fix restoring the TEXT cast
case "in", "notin": values := make([]string, 0) for _, v := range strings.Split(filter.Value.(string), ",") { if trimmed := strings.TrimSpace(v); trimmed != "" { values = append(values, trimmed) } } - return query.Where(goqu.Ex{field: goqu.Op{filter.Operator: values}}), nil + castField := goqu.Cast(goqu.I(field), "TEXT") + if filter.Operator == "in" { + return query.Where(castField.In(values)), nil + } + return query.Where(castField.NotIn(values)), nil