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.

Unable to query records with certain values

See original GitHub issue

Bug description

Prisma is unable to query database records filtered by values if those values are very specific amounts (e.g., 787.56 and 787.57).

How to reproduce

Create a database table and insert some values:

CREATE TABLE `demo` (
  `id` int NOT NULL AUTO_INCREMENT,
  `amount` decimal(11, 2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

INSERT INTO `demo` SET `amount` = 787.55;
INSERT INTO `demo` SET `amount` = 787.56;
INSERT INTO `demo` SET `amount` = 787.57;
INSERT INTO `demo` SET `amount` = 787.58;  

Add the model to the Prisma schema:

model Demo {
  id     Int   @id @default(autoincrement())
  amount Float

  @@map("demo")
}

Generate the Prisma client, then write some code:

const result55 = await prisma.demo.findMany({
	where: {
		amount: 787.55,
	},
});

console.log(result55);

const result56 = await prisma.demo.findMany({
	where: {
		amount: 787.56,
	},
});

console.log(result56);

const result57 = await prisma.demo.findMany({
	where: {
		amount: 787.57,
	},
});

console.log(result57);

const result58 = await prisma.demo.findMany({
	where: {
		amount: 787.58,
	},
});

console.log(result58);

Run that code, and receive the following output:

[ { id: 1, amount: 787.55 } ]
[]
[]
[ { id: 4, amount: 787.58 } ]

Expected behavior

To receive the following output:

[ { id: 1, amount: 787.55 } ]
[ { id: 2, amount: 787.56 } ]
[ { id: 3, amount: 787.57 } ]
[ { id: 4, amount: 787.58 } ]

Prisma information

generator client {
  provider      = "prisma-client-js"
  output        = "../generated-client"
  binaryTargets = ["darwin", "darwin-arm64", "debian-openssl-1.1.x", "linux-arm64-openssl-1.1.x"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model Demo {
  id     Int   @id @default(autoincrement())
  amount Float

  @@map("demo")
}

Environment & setup

  • OS: Debian Bullseye
  • Database: MySQL
  • Node.js version: v16.14.0

Prisma Version

prisma                  : 3.9.2
@prisma/client          : 3.9.2
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at .yarn/unplugged/@prisma-engines-npm-3.9.0-58.bcc2ff906db47790ee902e7bbc76d7ffb1893009-c1aff4e71f/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at .yarn/unplugged/@prisma-engines-npm-3.9.0-58.bcc2ff906db47790ee902e7bbc76d7ffb1893009-c1aff4e71f/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at .yarn/unplugged/@prisma-engines-npm-3.9.0-58.bcc2ff906db47790ee902e7bbc76d7ffb1893009-c1aff4e71f/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at .yarn/unplugged/@prisma-engines-npm-3.9.0-58.bcc2ff906db47790ee902e7bbc76d7ffb1893009-c1aff4e71f/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio                  : 0.457.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Jolg42commented, Sep 7, 2022

When using this SQL:

-- CreateTable
CREATE TABLE `demo` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `amount` DOUBLE NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

INSERT INTO `demo` SET `amount` = 787.55;
INSERT INTO `demo` SET `amount` = 787.56;
INSERT INTO `demo` SET `amount` = 787.57;
INSERT INTO `demo` SET `amount` = 787.58;  

Which is what Migrate generates from the following schema

model Demo {
  id     Int   @id @default(autoincrement())
  amount Float

  @@map("demo")
}

the queries return the expected results

[ { id: 1, amount: 787.55 } ]
[ { id: 2, amount: 787.56 } ]
[ { id: 3, amount: 787.57 } ]
[ { id: 4, amount: 787.58 } ]

When using the “decimal(11, 2)” SQL

CREATE TABLE `demo` (
  `id` int NOT NULL AUTO_INCREMENT,
  `amount` decimal(11, 2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB;

INSERT INTO `demo` SET `amount` = 787.55;
INSERT INTO `demo` SET `amount` = 787.56;
INSERT INTO `demo` SET `amount` = 787.57;
INSERT INTO `demo` SET `amount` = 787.58; 

npx prisma db pull --force will result in the following schema

model demo {
  id     Int     @id @default(autoincrement())
  amount Decimal @db.Decimal(11, 2)
}

And then I can reproduce the mentioned unexpected results:

[ { id: 1, amount: 787.55 } ]
[]
[]
[ { id: 4, amount: 787.58 } 

Can reproduce in 3.9.2 and in our internal dev version 4.4.0-dev.30

in 3.9.2 using Prisma.Decimal() throws TypeError: arg2.inputTypes is not iterable

But using new Prisma.Decimal() like the following works, in our internal dev version 4.4.0-dev.30!

  const result57 = await prisma.demo.findMany({
    where: {
      // amount: 787.57, // doesn't work
      amount: new Prisma.Decimal('787.57'), // works
    },
  });
[ { id: 1, amount: 787.55 } ]
[ { id: 2, amount: 787.56 } ]
[ { id: 3, amount: 787.57 } ]
[ { id: 4, amount: 787.58 } ]

Which means this will be fixed in 4.4.0

0reactions
Jolg42commented, Sep 7, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to run a query with the UniqueValues property - Office
This problem occurs because when you set the UniqueValues query property to Yes, a DISTINCT keyword is added to the resulting SQL statement....
Read more >
How to query for rows containing <Unable to read data> in a ...
The SELECT will work fine, but showing the Edit Top 200 Rows in ... Causes DBCC CHECKDB to check the database for column...
Read more >
Not able to get field value in SOQL query
In User object Field called ASM__C (Formula Field) and I am retrieving the records based on this field. But I am getting Null...
Read more >
Unable to query Account Fields - Salesforce Stack Exchange
This issue is almost certainly caused by Field Level Security . Click into each field and click the Set Field Level Security button....
Read more >
unable to query records with data in exponential value
Now the issue is this, In one table I'm able to find/search a particular row by using the exp value within where clause...
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