pg-promise returns integers as strings

后端 未结 3 1131
慢半拍i
慢半拍i 2020-12-03 03:14

I have this simple query to a table that contains a column of type bigint.

However when I query it, pg-promise returns this column\'s values as a strin

3条回答
  •  隐瞒了意图╮
    2020-12-03 03:52

    Another alternative, specifically if you're using JavaScript without BigInt support, is to cast the value to an int in the SQL query, as such:

    var ids = [180, 120];
    
    // Cast id_brand to an int to ensure it is not parsed as a string.
    db.any('SELECT id_brand::int, brand from catalog_brand WHERE id_brand in ($1:csv)', [ids])
        .then((data) => {
            // return results
        });
    

    Of course, this does not help you if id_brand has values larger than the maximum int.

提交回复
热议问题