pg-promise ,如何 select 与 where ... like date%

pg-promise , how to select with a where ... like date%

我在尝试获得以下 select 时有点卡住了:

id(int)  balance(int)  datetime(timestamp without timezone)
7        153           "2020-08-24 20:15:49"
8        115           "2020-08-24 20:16:13"
9        105           "2020-08-24 20:17:14"

我想select这样做

let date = moment().format("YYYY-MM-DD")
console.log(date) // 2020-08-24
let selectAddressSnapshotByDate = new PQ({text: "SELECT balance, datetime FROM table where datetime like '%' ", values: [date.toString()]})

我基本上想获取日期时间以程序的日期值开头的值

我现在收到以下错误:

error: operator does not exist: timestamp without time zone ~~ unknown

可能会出现问题,因为您有 TIMESTAMP 形式的时间信息,但它要求您有 TIMESTAMPTZ。如果对你有用

首先,您没有正确使用查询参数。参数不应该用单引号括起来。

那么:如果要处理日期,那就用日期函数,而不是字符串函数,比如like.

我会将您的查询表述为:

select balance, datetime 
from table 
where datetime >= ::date and datetime < ::date + '1 day'::interval