typeorm: Using "in" operator with uuid types causes "invalid input syntax" error
Issue type:
- bug report
Database system/driver:
-
postgresv11
TypeORM version:
-
latest0.2.26
With postgres, “in” operator is valid on UUID types:
SELECT x.* FROM my_table x WHERE x."_id" IN ('77dec6ee-8d39-4b73-825a-6190628d2953','7900b8c6-c239-45e1-9ca8-2d1a244eb881')
However, the following code throws an error:
repository.find({
where: {
_id: In(['77dec6ee-8d39-4b73-825a-6190628d2953', '7900b8c6-c239-45e1-9ca8-2d1a244eb881']),
}
});
QueryFailedError invalid input syntax for type uuid: "{"_type":"in","_value":["77dec6ee-8d39-4b73-825a-6190628d2953", "7900b8c6-c239-45e1-9ca8-2d1a244eb881"],"_useParameter":true,"_multipleParameters":true}"
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 9
- Comments: 21 (7 by maintainers)
I believe the answer to this question is in this other issue: https://github.com/typeorm/typeorm/issues/1985
All you have to do is use the new ‘…’ operator to spread the array inside the In clause of your query, like so:
Note the
:...keything, but I don’t see this’s being mentioned anywhere in the changelog… Am I missing anything?_Originally posted by @lednhatkhanh in https://github.com/typeorm/typeorm/issues/1985#issuecomment-383270029_
Similar effect for inside query builder…
throwing this error:
Interestingly, the search will work if I add the parameter value inside the query, but only if I use single quotes like here:
I have been able to solve this by following the instructions in this issue.
Essentially just change your query to
This is happening for
Rawas well.Logs:
I’ve tried using QueryBuilder instead, with the same result.
#7247 suggests that using
entityManager.getRespository(Request).findorentityManager.getRespository(Request).createQueryBuildermight work, but I got the same result with both.