Search code examples
node.jspg

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


Why I get this error:

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

code:

    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
      ]);

What I am doing wrong ? Maybe this error comes because the tsrange but idk how to solve it

can anyone help me to solve this issue

thank you very much!


Solution

  • The error message is pretty clear. Your statement requires 15 parameters, but you pass 16. You added parseInt(p.business_id) twice. It should be:

    [
      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
    ]