Repository navigation
Closed
prisma/prisma-engines
#2174Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: JsonScalar type `Json`topic: client apitopic: filterJson
Milestone
Description
Bug description
Number JSON filtering is not working as it should be with large number that are far apart from each other for example 50, 100
prisma:query SELECT "public"."Test"."id", "public"."Test"."metadata" FROM "public"."Test" WHERE (("public"."Test"."metadata"#>>ARRAY[$1]::text[]) >= $2 AND JSONB_TYPEOF(("public"."Test"."metadata"#>ARRAY[$3]::text[])) = $4)
OFFSET $5
TEST1 [
{
"id": 1,
"metadata": {
"price": 50
}
},
{
"metadata": {
"price": 100
}
}
]
prisma:query SELECT "public"."Test"."id", "public"."Test"."metadata" FROM "public"."Test" WHERE (("public"."Test"."metadata"#>>ARRAY[$1]::text[]) >= $2 AND JSONB_TYPEOF(("public"."Test"."metadata"#>ARRAY[$3]::text[])) = $4)
OFFSET $5
TEST2 [
{
"id": 1,
"metadata": {
"price": 50
}
}
]
How to reproduce
- copy paste the schema and index.ts code
- npx prisma migrate dev --name init
- ts-node index.ts
- spot the bug
Expected behavior
Two rows will be return if price is greater than or equal 50 instead of getting 1 row in TEST2 from console log.
Prisma information
Schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["filterJson"]
}
model Test {
id Int @id @default(autoincrement())
metadata Json
}
index.ts
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient({
log: ["query"]
})
async function main() {
const data1 = await prisma.test.findMany({
where: {
metadata: {
path: ['price'],
gte: 1
}
}
});
console.log("TEST1", JSON.stringify(data1, null, 2));
const data2 = await prisma.test.findMany({
where: {
metadata: {
path: ['price'],
gte: 50
}
}
});
console.log("TEST2", JSON.stringify(data2, null, 2));
}
main()
.catch((e) => {
throw e
})
.finally(async () => {
await prisma.$disconnect()
})
Environment & setup
- OS: Windows
- Database: PostgresSQL
- Node.js version: v16.4.2
Prisma Version
prisma : 2.26.0
@prisma/client : 2.26.0
Current platform : windows
Query Engine : query-engine 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine : migration-engine-cli 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 9b816b3aa13cc270074f172f30d6eda8a8ce867d
Studio : 0.408.0
Preview Features : filterJson
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.topic: JsonScalar type `Json`topic: client apitopic: filterJson

Activity
pantharshit00 commentedon Jul 11, 2021
I can reproduce this with
2.27.0-dev.59. Thanks for the detailed report.