【发布时间】:2020-05-22 19:03:20
【问题描述】:
我正在使用 node-postgres 模块和 node 13.5。我正在尝试在 postgres 时间图列中插入一个 unix 时间戳,它似乎在 dbeaver 中工作,但是当我运行代码时它不起作用。
CREATE TABLE public.test (
column1 timestamp NULL
);
当我运行插入时在 dbeaver 中:
insert into test (column1 ) values ( $1 )
它会打开一个对话框,我在我的参数中键入:to_timestamp(1) 我点击确定,它会毫无问题地插入我的表格。
但是当我使用这段代码时:
pool.query("INSERT INTO test (column1) VALUES ($1)", ["to_timestamp(1)"]);
我得到一个错误:
error: invalid input syntax for type timestamp: "to_timestamp(1)"
查询方法是模块中的方法。
如果我这样跑:
pool.query("INSERT INTO test (column1) VALUES (to_timestamp(1))", []);
有效。
似乎 nodejs 驱动程序在做一些与 dbeaver 驱动程序不同的事情。我做错了吗?有没有办法解决这个问题?如果可能的话,我想使用准备好的语句。
我无法改变的事情:
- 我的数据在 unix 时间戳中
- 列必须具有时间戳类型
任何帮助表示赞赏。
【问题讨论】:
标签: node.js postgresql node-postgres