PostgreSQL: `Int` type should be able to be mapped to `@db.BigInt`
See original GitHub issueProblem
At the moment, the only way to use PG’s int8
column type is by specifying BigInt
type in the schema, which maps to Js’s bigint
type. But there are use cases in which we want to use JS’s number
type. Can have a way of using PG’s int8
column type which maps to a number
type in JS?
I know maximum value for PostgreSQL’s int8 is 9223372036854775807
, which is out of range of JS’s number max value (9007199254740991
). But maybe that can be written as a warning in the documentation?
Suggested solution
We should be able to do:
model MyModel {
myBigNumber Int @db.BigInt
}
Alternatives
Can’t think of any.
Thanks 🙂
(related discussion: https://github.com/prisma/prisma/discussions/6948)
EDIT Fixed wrong claims about JS maximum value for number
Issue Analytics
- State:
- Created 2 years ago
- Reactions:23
- Comments:17 (1 by maintainers)
Top Results From Across the Web
Documentation: 9.1: Numeric Types - PostgreSQL
The types smallint, integer, and bigint store whole numbers, that is, numbers without fractional components, of various ranges. Attempts to store values outside ......
Read more >Entity Framework Data Type Mapping - Devart
PostgreSQL data types SSDL.NET
boolean boolean System.Boolean
smallint, int2 smallint System.Int16
integer, int4 int System.Int32
Read more >PostgreSQL® Data Types: Mappings to SQL, JDBC, and Java ...
Discovered what data types are available in PostgreSQL and determined the definitive mapping from PostgreSQL to SQL/JDBC to Java data types.
Read more >Data type support & mapping for PostgreSQL sources - Striim
PostgreSQL source type BigQuery Delta Lake MySQL Oracle Postgre...
bigint / int8 int64 bigint bigint int bingint
bigserial / serial8 int64 bigint bigint int bigserial
bit...
Read more >Supported Types and their Mappings | Npgsql Documentation
bigint, long, long, byte, short, int, float, double, decimal ... There are three rules that determine the PostgreSQL type sent for a parameter:....
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
My question is: how do I apply this large-scale to any model that returns bigints, when NodeJS is able to present them as
Number
? I don’t want to manually dotoNumber
everywhere I use the model. I think the best solution is that prisma provides that functionality natively, because all other solutions impose a big overhead in code, just to apply number to all bigints.What’s got me down about this issue is I prefer to store datetime as utc bigint’s. They’re just immeasurably easier to work with than the standard date format is. But now with Prisma I’m introduced to a lot of headaches with BigInt fields, I can’t seem to select anything from my database without seeing Javascript BigInt objects everywhere.
Which causes problems for a large number of reasons. JSON stringify is only one.
I guess I’m thinking about the database as a place to store data and I don’t really care very much if the value I get back from it is "the correct format’. I should at least I think be able to tell my schema that a field returns a number.