Sequelize returns a string for decimal types from postgres
See original GitHub issueIt’s returning strings for my decimal data types
I have a model with a DECIMAL column. Whenever I query that model the column is returned as a string.
When i try to get data from my postgres DB
app.get('/itens', function(req, res) {
models.itens.findAll().then(function(itens) {
res.json(itens);
});
});
It supposed to return a float value
The return always is a String value
{
"price": "196",
}
I am using
- Sequelize version: 5.21.2
- Node.js version: 10.15.3
- Operating System: mac Os
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect:
- I don’t know, I was using postgres, with connector library version 7.12.1 and database version 12
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Sequelize returns a string for decimal types #8019 - GitHub
I have a simple model with a DECIMAL column. Whenever I query that model the column is returned as a string rather than...
Read more >Postgres/Sequelize — returns a string for decimal/numeric type
Here I found a work around to make it returns as string in the code base, and it worked well for me.
Read more >why is my sequelize query that sums a decimal column ...
I don't know why it isn't stated in sequelize v4 docs, but v3 states that: An explicit cast is required on postgres. http://sequelize....
Read more >Data Types - Sequelize
DECIMAL (precision, scale) is meant to be a constrained decimal type. All, PostgreSQL, MariaDB, MySQL, MSSQL, SQLite, Snowflake, db2, ibmi. Sequelize DataType ...
Read more >Sequelize decimal type error - maciek ☁️
Sequelize returns a string instead of a number for decimal type.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Suggested workaround
This is the expected behavior for
decimal
, you should usefloat
ordouble
if you want to use thenumber
type in javascriptNonetheless, https://github.com/sequelize/sequelize/issues/14296 proposes a way to return
number
out of the boxI’ll close as this issue in favor of https://github.com/sequelize/sequelize/issues/8019