为什么我得到这个错误:
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
]);
我做错了什么?也许这个错误是因为 tsrange 但不知道如何解决它
谁能帮我解决这个问题
非常感谢!
尝试将 date_from 和 date_to 值组合成一个范围值,然后再将其传递给查询。
错误信息很清楚。您的语句需要 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
]