Postgres sequelize raw query to get count returns string value(Postgres sequelize 原始查询以获取计数返回字符串值)
问题描述
我在我的 node-express 服务器中使用 postgresql sequelize.
I am using postgresql sequelize in my node-express server.
当我运行以下 SQL 命令时,我得到一个字符串值作为结果.
When I run the following SQL Command, I am getting a string value for result.
我想获取此计数的 整数 值.
I want to get Integer value for this count.
SELECT count(id) from collaborators where id<3
结果:
count = [ { count: '1' } ]
有什么方法可以获取结果的数值吗?还是我总是需要使用 parseInt(count, 10) 来获取 int 值?
Is there any way to get number values for result? Or do I always need to use parseInt(count, 10) to get int value?
感谢您的帮助!
推荐答案
@DemtriOS 正确的是 count
返回 bigint
因此解释为 string
,您可以直接在查询中直接对它进行类型转换,如下所示:
@DemtriOS is correct that count
returns bigint
hence interpreted into string
, you can directly typecast it directly on your query like so:
SELECT COUNT(id)::int
FROM collaborators
WHERE id < 3
这篇关于Postgres sequelize 原始查询以获取计数返回字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Postgres sequelize 原始查询以获取计数返回字符串值


基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01