-
Notifications
You must be signed in to change notification settings - Fork 119
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
Support WHERE "column" = ANY($1)
#342
Comments
Hi @houten11, sorry for the poor described issue. I've checked the wiki. It do achieve the For array with length 1 (with WHERE "id" IN ($1) for 2: WHERE "id" IN ($1, $2); for 3: WHERE "id" IN ($1, $2, $3); And so on. For array with arbitrary length (with WHERE "id" = ANY($1); |
Sorry, skimmed over the issue description on the first read. Yeah, func ANY(expr Expression) Expression {
return Func("ANY", expr)
} This function now can be used as part of query: User.ID.EQ(IntExp(ANY(
Raw("#1", RawArgs{"#1": pq.Int32Array{1, 2, 3, 4}}), // arrays are not supported, so we have to use Raw
))), or User.ID.EQ(IntExp(ANY(
SELECT(...)...
))), |
Hi @houten11, thanks for the solution. But is it possible to add a With |
Hi @yz89122,
jet is a type safe library, so the types needs to match.
If we add In some cases we can avoid writing If you want to avoid func ANYi(exp Expression) IntExpression {
return IntExp(ANY(exp))
}
func ANYs(exp Expression) StringExpression {
return StringExp(ANY(exp))
} You can also wrap array constructor in a new method: func ARRAY(elems ...any) Expression {
return Raw("#1", RawArgs{"#1": pq.Array(elem)}),
} Now you can write: User.ID.EQ(ANYi(ARRAY(1, 2, 3, 4))
User.Name.EQ(ANYs(ARRAY("John", "Mike", "Tod"))) |
Hi @go-jet, one additional information, One more question: Is it possible to add postgres.
SELECT(table.User.AllColumns).
FROM(table.User).
WHERE(table.User.ID.EQ(postgres.ANY(ids))) Currently, the |
Actually, Strictly speaking, IN and ANY are Postgres "constructs" or "syntax elements", rather than "operators". In SQL they appear as function, so make sense to model as function.
Eventually it will be introduced as part of array support. |
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
As title, support the following query
Currently, I need to achieve this query by using
postgres.RawBool()
.Although the above query can be achieved through
IN ($1, $2, ...)
, for dynamic length array, it'll generate numbers of different queries forIN ($1)
,IN ($1, $2)
and so on. For databases there're different queries, that's not a good thing for databases.I.g.
SQL generated:
For
len(ids) = 1
:For
len(ids) = 2
:For
len(ids) = 3
:And so on.
Describe the solution you'd like
A clear and concise description of what you want to happen.
I hope there's a method
.EQ_ANY()
for columns.I.g.
The text was updated successfully, but these errors were encountered: