docs do not describe how bigint type is treated as string to avoid rounding issues
See original GitHub issueIssue type:
[ ] question [ ] bug report [ ] feature request [x] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.7
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I ran console.log(entity, typeof entity.myBigIntColumn)
and noticed that my column was a string instead of Number
. This makes sense because the maximum postgres bigint value is 9223372036854775807 and yet in JavaScript Number.MAX_SAFE_INTEGER
is 9007199254740991
. However, the documentation at http://typeorm.io/#/entities/column-types-for-postgres doesn’t mention that at all.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:33
- Comments:27 (5 by maintainers)
Top Results From Across the Web
Documentation: 15: 8.1. Numeric Types - PostgreSQL
Rounding might take place if the precision of an input number is too high. Numbers too close to zero that are not representable...
Read more >Decimal rounding issue in Informatica
There's no way (except with String datatypes) to cater for numbers with a higher number of digits. Everything above 28 digits will automatically...
Read more >Let's talk about big numbers in JavaScript - ITNEXT
Decimals with arbitrary precision can't be represented using the Number data type, as they will just get rounded to a smaller format.
Read more >math/big - Go Packages
Rounding is performed according to z's precision and rounding mode; and z's accuracy reports the result error relative to the exact (not rounded)...
Read more >BigDecimal (Java Platform SE 8 ) - Oracle Help Center
If no rounding mode is specified and the exact result cannot be ... setting is not 0, the rules of BigDecimal arithmetic are...
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
I just wanted to point out that this issue means that the type definitions for methods like
find
andfindOne
are incorrect. If you have an entity that looks like this:And you call
findOne
like this:The TypeScript compiler thinks that
person
has typePerson
because that is what the type definition forfindOne
specifies. But in reality the type of theperson.age
will bestring
instead ofnumber
. This can lead to some surprising and confusing errors.I’ll leave some bread crumbs because I got this to work for my application.
In creating the the TypeOrm connection, I’m using Nest but that doesn’t matter, you can add the option
And typescript 3.2 supports
bigint
types.We can therefor declare:
This works for me and presents no risk of overflow. I hope this helps.