postgresql - 如何根据 uuid 数组从用户中进行选择?

标签 postgresql uuid pg

如果我在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/

相关文章:

ruby-on-rails-3 - 无法使用 postgres 在 rails 3.2 中创建测试数据库

postgresql - postgres 事件触发器和功能不起作用

postgresql - 带 Postgresql 的 DBUnit 和列名区分大小写 - 它是如何工作的?

sql-server - 带有 SQL Server 的 postgresql

android - android设备UUID在什么情况下会发生变化?

java - 使用系统时间作为 UUID

arrays - Ruby PG Gem 使用 TextEncoder::Array 进行 SELECT WHERE fieldname IN exec_params

ruby-on-rails - Postgres 没有创建用户的权限

c# - 根据字符串生成UUID

node.js - PostgreSQL 错误 : relation does not exist on INSERT Statement