postgresql - 无法搜索字符变 [] 数组列
问题描述
我的 postgres 数据库表有一个列位置,它是 character varying[]
。在我的表格的nestjs实体中,我关注位置列-
@Column("character varying",{array:true})
location: string[];
我想要做的是搜索将参数作为位置传递的行。这是给我适当结果的原始查询-
select * from blogs where language @> '{"Spanish","English"}'
在我的nestjs服务中,如何实现上述查询?我试过这样做-
return await this.blogsRepo.find({
where: [
{
location: Any(body.locations)
}
]
})
body.locations
是这样的数组-
body.locations = ["Spanish","English"]
上面的 typeorm 解决方案给了我以下错误-
'找不到数据类型字符变化 [] 的数组类型'
可能的解决方案是什么?我会喜欢 typeorm 解决方案,因为我将原始查询执行作为我的最后一个选择。
提前致谢,
解决方案
你可以试试这个:
await this.blogsRepo.find({
where: `${body.locations} = ANY (location)`,
});
推荐阅读
- meteor - Meteor 包动态导入失败,模板化为弱依赖
- angular - 在Angular 8+中的网格和编辑页面之间传递对象的最佳实践
- python - 正则表达式从逗号分隔的字符串中删除某些字符串
- java - Android 8+ - 如何在 android 中以编程方式连接到 wifi 网络?
- java - Kafka消费者投票行为和顺序
- r - 没有 ifelse 的 R 向量化
- mysql - Vue.js Node.js MySQL Heroku 405 不允许 nginx
- php - 不推荐使用 each() 函数
- javascript - 防止图像在内存元素中被下载
- sql - Rails 活动记录按列的总和排序