如果我在heroku中查询postgres,它工作正常:
select * from users where users.user_id in ('', '')
但是如果通过 postman 将请求发送到index.js,则仅当有一个元素而不是$1时才有效:
select * from users where users.user_id in ($1)
我尝试转换:
users.user_id::text
users.user_id in ($1::text
和
= any( array ([]);
最佳答案
首先将您的 UUID 连接成一个字符串,并使用 ,
作为分隔符,然后将其作为参数传递给此查询:
select * from users where users.user_id = any(string_to_array($1, ',')::uuid[]);
或者这个:
select * from users where users.user_id = any(('{'||$1||'}')::uuid[]);
这是一种或多或少通用的方法,也可以用于其他类似的情况。
关于postgresql - 如何根据 uuid 数组从用户中进行选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73098533/