我在我的node-express服务器上使用postgresql sequelize。
当我运行以下SQL命令时,我得到一个结果的字符串值。
我希望获得此计数的整数值。
SELECT count(id) from collaborators where id<3
结果:
count = [ { count: '1' } ]
有没有办法获得结果的数值?或者我是否总是需要使用parseInt(count,10)来获取int值?
我感谢任何帮助!
根据这个https://www.postgresql.org/docs/8.2/static/functions-aggregate.html,count()函数返回bigint类型。因此,它将被解释为字符串。看起来像是显式转换为int是你必须要做的。所以,它是parseInt(count, 10)
。