当我尝试在数组数组中搜索一个数组值时,我收到了上述错误。我的代码:
sequelize.define('room', {
'id' : {'type' : DataTypes.INTEGER, 'primaryKey' : true, 'autoIncrement' : true},
'tutor' : {'type' : DataTypes.INTEGER, 'allowNull' : false},
'students' : {'type' : DataTypes.ARRAY(DataTypes.STRING), 'allowNull' : false},
'subject' : DataTypes.STRING,
'date_time' : DataTypes.DATE,
'status' : {'type' : DataTypes.STRING , 'defaultValue' : "active"},
}
)
var queryString = "Select * from rooms where status = :statusVar and students @> ANY(:stuArray::character varying[]) ORDER BY CASE when :orderingVar = 'date_time DESC' then date_time end DESC, case when :orderingVar = 'date_time' THEN date_time end ASC OFFSET :offsetNumber LIMIT :limitNumber;"
return sequelize.query(queryString,{
replacements:{
statusVar: status,
orderingVar: orderVar,
limitNumber: itemPerPage,
offsetNumber: ((pageNumber-1)*itemPerPage),
tutArray: '{' + tutorUserId.toString() +'}',
stuArray: ['{' + studName.toString() + '}']
},
type: sequelize.QueryTypes.SELECT})
其中studName = [Emily,John,Dexter];
我想查找“学生”栏中包含任何学生姓名的所有记录,例如Emily或John或Dexter
答案 0 :(得分:1)
我最终做了以下工作
var queryString = "Select * from rooms where students && :stuArray::varchar[] and status = :statusVar ORDER BY CASE when :orderingVar = 'date_time DESC' then date_time end DESC, case when :orderingVar = 'date_time' THEN date_time end ASC OFFSET :offsetNumber LIMIT :limitNumber;"
'&安培;&安培;'重叠(具有共同的元素)运算符Ex:ARRAY [1,4,3]&& ARRAY [2,1]返回true。请注意,运算符的右侧也应该是此格式的数组stuArray: ['{' + studName.toString() + '}']
,即['{Emily, John, Dexter}']