Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use array_contains on Json in Postgres #9325

Closed
joelrozen opened this issue Sep 20, 2021 · 1 comment
Closed

Unable to use array_contains on Json in Postgres #9325

joelrozen opened this issue Sep 20, 2021 · 1 comment
Labels
kind/bug A reported bug.

Comments

@joelrozen
Copy link

joelrozen commented Sep 20, 2021

Bug description

I have a Json field that will only ever contain an array (not an object). I have tried following this and I also read #8977 and upgraded from 2.3 to 3.0.2 but issue remains.

How to reproduce

Schema:

model Test {
  arrayField Json? @default("[]") @db.JsonB
}
await prisma.test.create({ data: { arrayField: ["test", "data"]})

await prisma.test.findMany({ where: { arrayField: { array_contains: ["test"] } } })
// ERROR: 
Unknown arg `array_contains` in where.arrayField.array_contains for type JsonNullableFilter. Available args:

type JsonNullableFilter {
  equals?: JsonNullValueFilter | Json
  not?: JsonNullValueFilter | Json
}

Even the typings only actually give equals or not

I have tried using Json / Json? using JsonB, not sertting defaults, all different combinations, but array_contains just does not exist in the where clause.

Expected behavior

expect path and array_contains to exist in the where filter.

Prisma information

generator client {
  provider = "prisma-client-js"
}

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

model User {
  id              String    @id @default(uuid())
  email           String    @unique
  number          String    @unique
  suburbs         Json?     @default("[]") @db.JsonB
  publicTransport Boolean   @default(true)
  flights         Boolean   @default(true)
  stripeId        String?
  subscriptionId  String?
  otpSecret       String
  otpLastRequest  DateTime?
  isActive        Boolean   @default(false)
  isVerified      Boolean   @default(false)

  @@map("user")
}
const users = await database.user.findMany({
    where: {
      suburbs: {
        //@ts-ignore
        array_contains: ["Lake Forest"],
      },
    },
  })

Environment & setup

postgres, macos, node 12.18.3

Prisma Version

prisma                  : 3.0.2
@prisma/client          : 3.0.2
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio                  : 0.423.0
@joelrozen joelrozen added the kind/bug A reported bug. label Sep 20, 2021
@joelrozen
Copy link
Author

Ah so turns out I need to enable this in the preview features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

1 participant