POSTGRES检查提供的值是否在类型数组的列中 [英] POSTGRES check if a provided value is present in the column of type array

查看:137
本文介绍了POSTGRES检查提供的值是否在类型数组的列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查列中是否存在值(数组(column_name text [])类型)。
作为服务器,我正在使用hapi并尝试通过查询从hapi中检查它。

I am trying to check whether a value if present in the column, which is of type array(column_name text[]). As a server i am using hapi and trying to check the same from hapi through query.

我编写的查询是(查询不起作用):

Query which i have written is(query is not working):

where: { column_name: { $in: { provided_value} }}

该列包含以下值:

{1234, 3456}

值的类型为text。

有人可以帮助我确定问题所在吗。

Can someone please help me to identify the issue.

预先感谢。

推荐答案

Sequelize不支持 ANY 的这种用法,他们似乎仅支持 IN
相反,您应该尝试包含操作符( @> ):

Sequelize does not support this use of ANY, they seem to only support its use like IN. Instead, you should try the contains operator (@>):

import {Op} from "sequelize";

MyModel.findAll({
  where: {
    column_name: {
      [Op.contains]: [provided_value]
    }
  }
});

这将生成类似

SELECT * FROM "MyModel" WHERE column_name @> '{"provided_value"}';

这篇关于POSTGRES检查提供的值是否在类型数组的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆