Skip to content

JSON number filtering bug #8224

Closed
prisma/prisma-engines
#2174

Description

@firmanjml

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

  1. copy paste the schema and index.ts code
  2. npx prisma migrate dev --name init
  3. ts-node index.ts
  4. spot the bug

Expected behavior

Database Data
image

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

Activity

  1. added
    kind/bug
    on Jul 11, 2021
  2. added
    bug/0-unknown
    topic: Json
    on Jul 11, 2021
  3. pantharshit00 commented on Jul 11, 2021

    @pantharshit00
    Contributor

    I can reproduce this with 2.27.0-dev.59. Thanks for the detailed report.

  4. added
    bug/2-confirmed
    and removed
    bug/0-unknown
    on Jul 11, 2021
  5. added this to the 2.30.0 milestone on Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug/2-confirmedkind/bugtopic: Jsontopic: client apitopic: filterJson

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions