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 原始查询以获取计数返回字符串值
基础教程推荐
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
