Open
Description
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
SELECT *
FROM "user"
WHERE "id" = ANY($1); -- $1 is array
Currently, I need to achieve this query by using postgres.RawBool()
.
var ids []uuid.UUID
postgres.
SELECT(model.User.AllColumns).
FROM(model.User).
WHERE(eqAny(model.User.ID, ids))
func eqAny(column jet.Column, values any) postgres.BoolExpression {
return postgres.RawBool(fmt.Sprintf(`"%s".%s = ANY(#values)`, column.TableName(), column.Name()), jet.RawArgs{"#values": values})
}
Although the above query can be achieved through IN ($1, $2, ...)
, for dynamic length array, it'll generate numbers of different queries for IN ($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
:
SELECT *
FROM "user"
WHERE "id" IN ($1);
For len(ids) = 2
:
SELECT *
FROM "user"
WHERE "id" IN ($1, $2);
For len(ids) = 3
:
SELECT *
FROM "user"
WHERE "id" IN ($1, $2, $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.
var ids []uuid.UUID
postgres.
SELECT(model.User.AllColumns).
FROM(model.User).
WHERE(model.User.ID.EQ_ANY(ids))