POSTGRES check if a provided value is present in the column of type array

删除回忆录丶 提交于 2019-12-11 06:59:18

问题


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} }}

The column contains the values as:

{1234, 3456}

The values are of type text.

Can someone please help me to identify the issue.

Thanks in advance.


回答1:


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]
    }
  }
});

This will generate something like

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


来源:https://stackoverflow.com/questions/58536125/postgres-check-if-a-provided-value-is-present-in-the-column-of-type-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!