Hi guys. I have an entity and I want to insert int...
# orm-help
m
Hi guys. I have an entity and I want to insert into it only those rows from the array that have not yet existed according to my uniqueness condition (a set of 4 fields). I have the following code. But sometimes, nevertheless, for some reason, a uniqueness error flies out. Can someone explain why?
r
Could you share your schema so that I can check?
m
Of course
No idea?
r
Let me reproduce with a sample schema and get back to you on this.
All the records in this
copied
array are unique right?
m
They are not necessarily unique. As I understand it, thanks to the transactional, the upsert does not require uniqueness in the array. But I can try to conduct a test with an array filtered from duplicates
@Ryan Do you need a text version of a complete schema?
r
Yes that would be great!
But I can try to conduct a test with an array filtered from duplicates
If the combined key is not unique, then it will throw an error.
m
Please help me figure out why this is so. Here is my logic: let’s say we are trying to insert records
[(1, 1), (2, 2), (1, 1)]
. The first two records will be inserted without problems. When we get to the last entry
(1, 1)
, The prisma will transactionally check whether there is already such a record in the database, if not, then insert, if there is, then update (in my example - the update is fictitious, in fact nothing will happen). Of course, all three inserts happen in parallel, but again, thanks to the transactional upsert operation, I expect that uniqueness errors should not occur here in any case
r
In that case, there should be no errors. Let me check with sample values.
m
I will send in private messages our scheme and working data set, if you do not mind
👍 1