为什么我得到这个错误:
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,但idk如何解决它
谁能帮我解决这个问题
非常感谢!
2条答案
按热度按时间qvtsj1bj1#
错误信息非常清楚。您的语句需要15个参数,但您传递了16个。您添加了
parseInt(p.business_id)
两次。它应该是:xam8gpfp2#
尝试将date_from和date_to值合并为单个范围值,然后再将其传递给查询。