wag*_*gng 8 javascript postgresql node.js sequelize.js
我在我的 Node-Express 服务器中使用 postgresql Sequelize。
当我运行以下 SQL 命令时,我得到结果的字符串值。
我想获得此计数的整数值。
SELECT count(id) from collaborators where id<3
Run Code Online (Sandbox Code Playgroud)
结果:
count = [ { count: '1' } ]
Run Code Online (Sandbox Code Playgroud)
有什么方法可以获取结果的数值吗?或者我总是需要使用parseInt(count, 10)来获取 int 值?
我很感激任何帮助!
Mik*_*Chu 10
@DemtriOS是正确的,count返回bigint因此解释为string,您可以直接在查询上直接将其类型转换,如下所示:
SELECT COUNT(id)::int
FROM collaborators
WHERE id < 3
Run Code Online (Sandbox Code Playgroud)
根据此https://www.postgresql.org/docs/8.2/static/functions-aggregate.html, count() 函数返回 bigint 类型。因此,它将被解释为字符串。看起来您必须执行显式转换为 int 的操作。所以,parseInt(count, 10)确实如此。
| 归档时间: |
|
| 查看次数: |
4861 次 |
| 最近记录: |