Greetings, friends - I’m somewhat new to prisma (l...
# orm-help
d
Greetings, friends - I’m somewhat new to prisma (loving it so far), so this may be a dumb question, but I couldn’t find the answer in the docs or searching for it. I’m trying to add null values to an integer array in Postgres. I have a simple model defined as
Copy code
model foo {
  id   String     @id
  bar Int[]
}
when I have:
bar = [0, 0]
and call
Copy code
prisma.foo.create({
  data: {
    bar
  },
the array is saved in the database, but when I try to set one of the values to null
bar = [null, 0]
I get a vague error
failed: {"clientVersion":"3.12.0"}
I tried turning on extra debug logging, but I’m not getting any useful info. I can also directly update the row directly in postgres without any issues ( … set bar = ‘{null,0}’) Is it possible to set null values in an integer array through prisma? I appreciate any help you can provide.
j
I'm not an expert on Prisma, but it looks like it's failing because of a type check on the array value. Prisma is probably assuming that you don't want or need to store that null value in an integer array and isn't letting you do it. Can you create an enum to handle your int + allow null values, then change
bar Int[]
to
bar YourEnum[]
?
actually @david, can you try sending
undefined
instead of
null
?
I remember reading somewhere in the docs about undefined being preferential to null
d
Thanks @James L - I think you’re right about having to use an enum that supports nulls