最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 7浏览 0评论

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

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

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

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

SELECT count(id) from collaborators where id<3

结果:

count =  [ { count: '1' } ]

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

我感谢任何帮助!

回答如下:

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

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

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

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

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

SELECT count(id) from collaborators where id<3

结果:

count =  [ { count: '1' } ]

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

我感谢任何帮助!

回答如下:

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

发布评论

评论列表 (0)

  1. 暂无评论