Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql sequelize原始查询列不';不存在_Sql_Node.js_Postgresql_Sequelize.js - Fatal编程技术网

Sql sequelize原始查询列不';不存在

Sql sequelize原始查询列不';不存在,sql,node.js,postgresql,sequelize.js,Sql,Node.js,Postgresql,Sequelize.js,我试图使用原始查询,但我得到了错误。 为什么它认为test是一个列名 “测试”列不存在 module.exports = { getUser(req, res){ var sql = 'SELECT * FROM Users As Users WHERE Users.username = "test"' //Get the username of the user //Search the Users_matches databse for their userna

我试图使用原始查询,但我得到了错误。 为什么它认为test是一个列名

“测试”列不存在

module.exports = {

  getUser(req, res){
    var sql = 'SELECT * FROM Users As Users WHERE Users.username = "test"'
    //Get the username of the user
    //Search the Users_matches databse for their username and join it with the
    db.sequelize.query(sql, { type: sequelize.QueryTypes.SELECT})
    .then(result => {
      return res.status(201).send({
        result
      });
    })
}

您可以跳过值“test”。这很有效

const User = sequelize.define('User', {
  username: Sequelize.STRING,
});

sequelize.sync({ force: true })
  .then(() => {
    var sql = 'SELECT * FROM "Users" as "Users" WHERE username = \'test\'';
    sequelize.query(sql, { type: sequelize.QueryTypes.SELECT })
      .then(result => {
        console.log(result);
      });
  });

标准SQL使用单引号表示字符串文字,双引号表示标识符(如表名和列名)。