我收到此错误的原因:

error: bind message supplies 16 parameters, but prepared statement "" requires 15

代码:

    const r1 = await client.query(`
        INSERT INTO booking 
          (client_id, car_id, business_id, pick_up_station_id, 
            return_station_id, type, text, from_date, to_date, booking_range, km_free, km_extra, km_overdrawn, excess_back)
          VALUES
          ($1, $2, $3, $4, $5, $6, $7, $8, $9, tsrange($10, $11, '()'), $12, $13, $14, $15) RETURNING ID;
    `, [
        p.client_id !== '' ? parseInt(p.client_id) : null, 
        parseInt(p.car_id), parseInt(p.business_id), 
        parseInt(p.business_id),
        p.pick_up_station_id, 
        p.return_station_id, 
        p.type, 
        p.notice, 
        new Date(p.date_from),
        new Date(p.date_to),
        new Date(p.date_from),
        new Date(p.date_to),
        parseInt(p.free_km),
        parseInt(p.extra_km),
        0,
        0
      ]);

我做错了什么?也许这个错误的出现是因为这个范围但不知道如何解决它

有人能帮我解决这个问题吗?

非常感谢!

推荐答案

错误信息非常清楚.您的语句需要15个参数,但您传递了16个.您两次添加了parseInt(p.business_id).它应该是:

[
  p.client_id !== '' ? parseInt(p.client_id) : null,
  parseInt(p.car_id), // Removed parseInt(p.business_id)
  parseInt(p.business_id),
  p.pick_up_station_id,
  p.return_station_id,
  p.type,
  p.notice,
  new Date(p.date_from),
  new Date(p.date_to),
  new Date(p.date_from),
  new Date(p.date_to),
  parseInt(p.free_km),
  parseInt(p.extra_km),
  0,
  0
]

Node.js相关问答推荐

try 使用Puppeteer抓取Twitter时数组空

如何解决TypeError:requ.isAuthenticated不是函数错误?

GitLab SAST中的Nodejcan未找到匹配项

Mongoose-不会更新数组中的属性值

在对象的嵌套数组中使用$lookup,创建多个记录作为响应,mongodb

创建查询以展开数组并筛选出具有特定值的元素之后的元素

我收到警告:发现函数rs-ms-v1不受支持的运行时nodejs18.x× 不受支持的运行时

找不到 vue-template-compiler@2.6.14 的匹配版本 | Shopware 6.5 更新后的 node 问题

在 TypeScript 中正确键入 MongoDB find 方法

DynamoDB 分页数据检索

在 Nest 项目上运行 Jest 测试时,我的文件无法找到一个在测试之外没有任何问题的模块

npm 在 Windows 终端中不工作

Axios 响应循环通过函数只返回第一个映射对象的结果

将 express js app.use() 移动到另一个文件

为什么我的react 表单不能正常工作?

为什么我的 Heroku Express API 数据是持久的,即使它只是来自一个变量

2 x 匹配标准显示没有结果

搜索MongoDB条目的正确方法是'_id';在 node 中

如何在 Node.js 中使用 chmod

如何调试 Gulp 任务?