无法搜索 character varying[] 数组列

Not able to search through character varying[] array column

我的 postgres 数据库 table 有一个列位置是字符 varying[]。在我的 table 的 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)`,
});

根据 typeorm 文档,没有办法/内置 typeorm 运算符等同于 @> 运算符。

所以实现我想要的唯一方法是生成一个完整的查询,然后使用 Repository.query() 方法执行它。

到目前为止似乎有效!