0

If I use the Prisma explorer or MySql Workbench I get the correct query Result but with queryRaw in my code, I get numbers that slightly vary from the correct result. I can't figure out whats wrong and nedd help :) Thx!

SELECT * FROM (
    SELECT name, steamid, MATCH (name) AGAINST (${name}) AS relevance FROM players ORDER BY relevance  DESC LIMIT 10
  ) as x 
WHERE relevance > 0 

The correct result from Workbench or Prisma Explorer (name='jona')

Jona    76561199076734574   16.340665817260742
⁧⁧Jona    76561198218642855   16.340665817260742

Incorrect result from queryRaw

"players": [
        {
            "name": "⁧⁧Jona",
            "steamid": 76561198218642850,
            "relevance": 16.340665817260742
        },
        {
            "name": "Jona",
            "steamid": 76561199076734580,
            "relevance": 16.340665817260742
        }
    ]

My Code

const players = await prisma.$queryRaw`
  SELECT * FROM (
    SELECT name, steamid, MATCH (name) AGAINST (${name}) AS relevance FROM players ORDER BY relevance  DESC LIMIT 10
  ) as x 
  WHERE relevance > 0 
`;

Prisma Schema

model players {
  steamid                BigInt                   @id @unique(map: "steamid") @db.UnsignedBigInt
  name                   String                   @db.VarChar(32)
  kills                  Int                      @db.UnsignedMediumInt
  pvpdeaths              Int                      @db.UnsignedMediumInt
  pvedeaths              Int                      @db.UnsignedMediumInt
  suicides               Int                      @db.UnsignedMediumInt
  first_time_seen        DateTime                 @default(now()) @db.Timestamp(0)
  player_achievements    player_achievements[]
  player_wipe_stats      player_wipe_stats?
  pvelog_with_dublicates pvelog_with_dublicates[] @ignore

  @@fulltext([name], map: "name")
}

I have checked if the in put is correct and it should be. I also think the schema is correct because it works in the Explorer. So i think the error is in my code thit the `queryRaw` funtion.

Eon Sberk
  • 38
  • 5
  • 1
    Those numbers (`76561198218642855`, etc.) are beyond the value where the IEEE-754 double-precision floating point numbers used by JavaScript (and many other languages) are no longer precise even at the whole-number scale. The number literal `76561198218642855` results in the number `76561198218642850`, for instance. If you need to handle integer numbers that large, transfer them as strings, and use [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). – T.J. Crowder Mar 29 '22 at 09:38
  • (FWIW: The last "safe" integer is `Number.MAX_SAFE_INTEGER`, which is `9007199254740991`. You can still add 1 to that and get a valid result: `9007199254740992`. But you can't add 1 to *that* and get a valid result. The next number the format can represent is 2 higher: `9007199254740994`.) – T.J. Crowder Mar 29 '22 at 09:40

0 Answers0