簡體   English   中英

在 node-postgres insert 語句中使用 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($1, $2) RETURNING data_id",
          [ to_timestamp(sDateTime,'YYYY-MM-DD HH24:MI:SS'), to_timestamp(eDateTime,'YYYY-MM-DD HH24:MI:SS') ]
    );

這是我的控制台 output:

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 的表列都是timestamp類型

請問有什么想法嗎?

參數沒有插到SQL語句中,而是在to_timestamp中執行了to_timestamp function,導致報錯。

使用類似的東西

data = await pool.query(        
      "INSERT INTO my_table (window_start, window_end) VALUES (to_timestamp($1, 'YYYY-MM-DD HH24:MI:SS'), to_timestamp($2, 'YYYY-MM-DD HH24:MI:SS') RETURNING data_id",
          [ sDateTime, eDateTime ]
    );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM