Numeric data type is returned as String
See original GitHub issueHi,
firstly thanks for this module, it’s really great. I have found a problem in numeric
data type. It’s parsed as String.
Maybe I did something wrong or I have used bad DB type. Thanks for any advice.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
knex postgres returns strings for numeric/decimal values
Any way to override this behavior? If you are going to convert decimal number strings -> javascript numbers you must be extra careful...
Read more >Converting from Numeric to String :: Data Types (Programming)
The char function converts integers to Unicode character codes and returns a string composed of the equivalent characters: x = [77 65 84...
Read more >Type Conversion Functions - Microsoft Support
Returns "ProductID",converts the values in "Discount" field into Double for numeric values and String for Non-numeric values. VBA examples. Note: Examples that ...
Read more >API - Datatypes | Tedious
Type Constant1 JavaScript Result set Parameter
Exact numerics Exact numerics Exact numerics Exact numerics
bit TYPES.Bit Boolean ✓ ✓
tinyint TYPES.TinyInt Number ✓ ✓
Read more >The Type Hierarchy - SQLAlchemy 1.4 Documentation
The “CamelCase” datatypes¶. The rudimental types have “CamelCase” names such as String , Numeric , Integer , ...
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 FreeTop 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
Top GitHub Comments
Numeric type is oid 1700, so you can add this in your app.js or similar:
This actually does depend on your column type (http://www.postgresql.org/docs/9.4/static/datatype-numeric.html)
The type parsing here is handled by https://github.com/brianc/node-pg-types
If you dig into the readme, you’ll see an example about int8 (64 bit). Those can’t be parsed using
parseInt
because JS doesn’t support 64 bit ints.If you use a specific int type (smallint / 2 bytes, integer / 4 bytes) you’ll get the
Number
you’re expecting. But because numeric can be way larger thanNumber.MAX_SAFE_INTEGER
, the only safe way to parse it is to return a string with full precision.The good news is that if you know your numerics are within JS’s range, you can override the parser as instructed over at pg-types. Or, even better, you can use a more restrictive column type and it’ll happen automatically.