question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PostgreSQL: `Int` type should be able to be mapped to `@db.BigInt`

See original GitHub issue

Problem

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:open
  • Created 2 years ago
  • Reactions:23
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
MartinMuzatkocommented, Apr 27, 2022

The whole point of my examples was showing how to make TypeScript return the right types when you convert BigInts to numbers in an object. So i don’t really understand what you are saying here.

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 do toNumber 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.

3reactions
Kequccommented, Nov 5, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found