在 node-postgres 插入语句中使用 to_timestamp 时出错
Error when using to_timestamp in node-postgres insert statement
我正在使用 node-postgres 并尝试使用 to_timestamp 并收到错误:
ReferenceError: to_timestamp is not defined
这是我的代码:
let sDate = format(parseISO(myStartDate),'dd/MM/yyyy')
let sTime = format(parseISO(myStartTime), 'HH:mm:ss')
let sDateTime = `${sDate} ${sTime}`
let eDate = format(parseISO(myEndDate),'dd/MM/yyyy')
let eTime = format(parseISO(MyEndTime), 'HH:mm:ss')
let eDateTime = `${eDate} ${eTime}`
console.log(sDate, sTime, sDateTime)
console.log(eDate, eTime, eDateTime)
data = await pool.query(
"INSERT INTO my_table (window_start, window_end ) VALUES(, ) RETURNING data_id",
[ to_timestamp(sDateTime,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(eDateTime,'YYYY-MM-DD HH24:MI:SS') ]
);
这是我的控制台输出:
25/05/2021 19:56:40 25/05/2021 19:56:40
25/05/2021 19:56:40 25/05/2021 19:56:40
但是 ReferenceError: to_timestamp is not defined
出错
请注意,window_start 和 window_end 的 table 列都是 timestamp
类型
有什么想法吗?
SQL语句中没有插入参数,而是在Javascript中执行了to_timestamp
函数,所以报错
使用类似
的东西
data = await pool.query(
"INSERT INTO my_table (window_start, window_end) VALUES (to_timestamp(, 'YYYY-MM-DD HH24:MI:SS'), to_timestamp(, 'YYYY-MM-DD HH24:MI:SS') RETURNING data_id",
[ sDateTime, eDateTime ]
);
我正在使用 node-postgres 并尝试使用 to_timestamp 并收到错误:
ReferenceError: to_timestamp is not defined
这是我的代码:
let sDate = format(parseISO(myStartDate),'dd/MM/yyyy')
let sTime = format(parseISO(myStartTime), 'HH:mm:ss')
let sDateTime = `${sDate} ${sTime}`
let eDate = format(parseISO(myEndDate),'dd/MM/yyyy')
let eTime = format(parseISO(MyEndTime), 'HH:mm:ss')
let eDateTime = `${eDate} ${eTime}`
console.log(sDate, sTime, sDateTime)
console.log(eDate, eTime, eDateTime)
data = await pool.query(
"INSERT INTO my_table (window_start, window_end ) VALUES(, ) RETURNING data_id",
[ to_timestamp(sDateTime,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(eDateTime,'YYYY-MM-DD HH24:MI:SS') ]
);
这是我的控制台输出:
25/05/2021 19:56:40 25/05/2021 19:56:40
25/05/2021 19:56:40 25/05/2021 19:56:40
但是 ReferenceError: to_timestamp is not defined
请注意,window_start 和 window_end 的 table 列都是 timestamp
有什么想法吗?
SQL语句中没有插入参数,而是在Javascript中执行了to_timestamp
函数,所以报错
使用类似
的东西data = await pool.query(
"INSERT INTO my_table (window_start, window_end) VALUES (to_timestamp(, 'YYYY-MM-DD HH24:MI:SS'), to_timestamp(, 'YYYY-MM-DD HH24:MI:SS') RETURNING data_id",
[ sDateTime, eDateTime ]
);