查询在节点中不起作用,但在postgres中工作

时间:2018-05-24 11:05:30

标签: node.js postgresql node-postgres

节点版本 - 8.9.4 pg模块版本 - 7.4.3

此查询

UPDATE test.new_orders
SET properties = properties || '{"statusid":1,"updatedAt":"2018-5-24 14:51:43"}'
WHERE to_timestamp((properties ->> 'updatedAt'),'YYYY-MM-DD HH24:MI:SS.US') <= now() - INTERVAL '20 seconds'
AND properties ->> 'partitionid' = '6';
节点中的

给出了

    Result {
    command: 'UPDATE',
    rowCount: 0,
    oid: null,        rows: [],        fields: [],
    _parsers: [],        RowCtor: null,        rowAsArray: false,
    _getTypeParser: [Function: bound ] }

但在postgres中它总是更新3行。 重点是什么? 怎么处理这个?

P.S。 这是我的方法

      getUpdatableOrdersAndUpdateStatuses(partitionid,orderProperties,interval) {
    return new Promise((resolve, reject) => {
        let query = `UPDATE test.new_orders
                        SET properties = properties || '${orderProperties}'
                     WHERE to_timestamp((properties ->> 'updatedAt'),'YYYY-MM-DD HH24:MI:SS.US') <= now() - INTERVAL '${interval}'
                     AND properties ->> 'partitionid' = '${partitionid}';`;
                     // test query = 'select * from test.new_orders'
                     console.log(query);         
        SQL.query(query, (err, res) => {
            if (err) {
                console.log(err);
                return reject(err);
            }
            console.log(res);
            return resolve(true);
        })
    });
}

测试查询(select * from test.new_orders)给出正常结果

也是数据

orderid properties

5281    {"tarifid": "1", "statusid": 1, "createdAt": "2018-05-24T13:40:57.544955", "updatedAt": "2018-5-24 14:46:49", "partitionid": "6"}

15  {"tarifid": "1", "statusid": 1, "createdAt": "2018-05-24T14:38:57.609023", "updatedAt": "2018-5-24 14:46:49", "partitionid": "6"}

152 {"tarifid": "1", "statusid": 1, "createdAt": "2018-05-24T14:39:11.655951", "updatedAt": "2018-5-24 14:46:49", "partitionid": "6"}

真棒!!!忘了加入AT TIME ZONE'Asia / Yerevan'

0 个答案:

没有答案