gpt4 book ai didi

arrays - Sequelize 数据库错误: operator does not exist: character varying[] @> character varying

转载 作者:行者123 更新时间:2023-11-29 13:20:50 25 4
gpt4 key购买 nike

当我尝试在数组数组中搜索一个数组值时出现上述错误。我的代码:

    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

最佳答案

我最终做了以下并且它起作用了

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;"

'&&' 是重叠(具有共同元素)运算符 例如:ARRAY[1,4,3] && ARRAY[2,1] 返回 true。请注意,运算符的右侧也应该是这种格式的数组 stuArray: ['{' + studName.toString() + '}'] 即,['{Emily, John , 德克斯特}']

关于arrays - Sequelize 数据库错误: operator does not exist: character varying[] @> character varying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42064376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com