繁体   English   中英

Postgres sequelize 原始查询以获取计数返回字符串值

[英]Postgres sequelize raw query to get count returns string value

我在 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)是。

@DemtriOS是正确的, count返回bigint因此解释为string ,您可以直接在查询中直接键入它,如下所示:

SELECT COUNT(id)::int
FROM collaborators
WHERE id < 3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM