我正在尝试从sequelize.js对我的postgres数据库运行一个函数。当我通过RazorSQL(数据库IDE)运行它时,该函数工作正常,但是从节点服务器上的sequelize.js运行它时会抛出错误。
我尝试了有和没有参数的两个函数。
节点服务器上的CoffeeScript
query = "SELECT * FROM order.base_orders(); "
sequelize.query(query, null, {raw: true}).success (rows) =>
deferred.resolve rows
.error (error) =>
deferred.reject error
它返回以下错误。
{
"error": {
"name": "error",
"length": 216,
"severity": "ERROR",
"code": "42883",
"hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
"position": "15",
"file": "parse_func.c",
"line": "306",
"routine": "ParseFuncOrColumn",
"sql": "SELECT * FROM order.base_orders(); "
}
}
答案 0 :(得分:0)
错误说明:您需要投放数据,例如: select foo((?)::int)
,或确保您使用正确数量的参数调用它 - 或确保它存在,就此而言。
答案 1 :(得分:0)
您做错了。函数只能在列选择区域中调用。喜欢
select function(arguments)
随后将是这样
const query = "SELECT searchProducts('search query');"
return sequelize.query(query);
请注意,sequelize是我像下面创建的Sequelize db会话
var sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'mysql'|'sqlite'|'postgres'|'mssql',
pool: {
max: 5,
min: 0,
idle: 10000
},
// SQLite only
storage: 'path/to/database.sqlite'
});