【发布时间】:2020-12-22 20:43:11
【问题描述】:
我目前正在使用pg-promise 库将多个值插入数据库中,格式如下:
const cs = new pgp.helpers.ColumnSet(['booking_id', {name:'timeslot', cast:'timestamp'}], {table: 'booking'});
// data input values:
const values = [];
bookings.forEach(slot => {
values.push({booking_id: booking_id, timeslot: slot});
});
我需要时隙作为时间戳。然而,它作为像
这样的值进入 API1515586500.0
使用上面的cast 属性,我的查询得到这样解决
insert into "booking"("booking_id","timeslot") values(1,'1515586500.0'::timestamp)
但是这会引发cannot cast type numeric to timestamp without time zone的错误
如果我使用 to_timestamp 函数,但是这可以满足我的需要,例如
insert into "booking"("booking_id","timeslot") values(1,to_timestamp('1515586500.0'));
有什么方法可以让 pg-promise 使用 to_timestamp 而不是 ::timestamp 表示法?
【问题讨论】:
标签: pg-promise