Postgres sequelize raw query to get count返回字符串值

问题描述 投票:0回答:1

我在我的node-express服务器上使用postgresql sequelize。

当我运行以下SQL命令时,我得到一个结果的字符串值。

我希望获得此计数的整数值。

SELECT count(id) from collaborators where id<3

结果:

count =  [ { count: '1' } ]

有没有办法获得结果的数值?或者我是否总是需要使用parseInt(count,10)来获取int值?

我感谢任何帮助!

javascript node.js postgresql sequelize.js
1个回答
1
投票

根据这个https://www.postgresql.org/docs/8.2/static/functions-aggregate.html,count()函数返回bigint类型。因此,它将被解释为字符串。看起来像是显式转换为int是你必须要做的。所以,它是parseInt(count, 10)

© www.soinside.com 2019 - 2024. All rights reserved.