【问题标题】:error: invalid input syntax for type timestamp错误:类型时间戳的输入语法无效
【发布时间】:2019-02-11 12:22:33
【问题描述】:

我使用pg 节点模块连接到 PostgreSQL,我正在尝试执行这个查询:

  const res = await client.query(`SELECT number_transactions FROM transaction.city_unique_dates WHERE date_day_timestamp = TIMESTAMP '$1:value-$2:value-$3:value'`, 
  ['2014', '04', '12'])
  console.log(res)

但我收到以下错误:

error: invalid input syntax for type timestamp: "$1:value-$2:value-$3:value"

有人知道 timestamp 出了什么问题吗? 我对 Node.js 很熟悉,但对 postgres 不太熟悉

https://node-postgres.com/

【问题讨论】:

    标签: javascript node.js postgresql timestamp


    【解决方案1】:

    你必须试试这个:

    const res = await client.query(`SELECT number_transactions FROM 
    transaction.city_unique_dates WHERE date_day_timestamp = TIMESTAMP("2014-04-12")`)
    console.log(res)
    

    【讨论】:

    • 我认为它不适用于括号,但参数变量会显示错误。如果您将答案作为准备好的语句查询,那就太好了。
    • 这个有效:res = await client.query(SELECT timestamp '2001-09-28 01:00' as message, [])。而这个不起作用: res = await client.query(SELECT timestamp '$1:value-09-28 01:00' as message, [2001])
    • 是的,这是我的错误 这将有效:TIMESTAMP '2008-2-23 12:23:34.456'
    猜你喜欢
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 2020-11-05
    • 1970-01-01
    相关资源
    最近更新 更多