我的 postgres 数据库表有一个列位置是字符 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 解决方案给了我以下错误-
'could not find array type for data type character varying[]'
可能的解决方案是什么?我会喜欢 typeorm 解决方案,因为我将原始查询执行作为最后的选择。
提前致谢
最佳答案
你可以试试这个:
await this.blogsRepo.find({
where: `${body.locations} = ANY (location)`,
});
关于postgresql - 无法搜索 character varying[] 数组列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57408935/