问题
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