【发布时间】:2020-10-13 20:31:08
【问题描述】:
我正在尝试将具有不同小时间隔的时间戳动态插入 Postgres (12.1)、NodeJS 10.15.3 和 Knex。
通过 Postico 直接插入 Postgres,NOW() + INTERVAL 'n hours' 格式可以正常工作:
insert into users (first_name, updated_at)
values ('Bob', NOW() + INTERVAL '2 hours');
通过 Knex 插入时,
row.updated_at = `NOW() + INTERVAL '2 hours'`;
我收到错误:
invalid input syntax for type timestamp with time zone: "NOW() + INTERVAL '2 hours'"
通过query.toString()输出查询,我看到区间已经转换成
'NOW() + INTERVAL ''2 hours'''
我怎样才能以正确的格式插入它?
【问题讨论】:
-
你能发布示例代码吗?
标签: node.js postgresql knex.js