I have an employee table (id, fname, lname etc.) and a skills table (id, skill_name). They are linked by way of a junction table emp_skillz (id, emp_id, skill_id).
I have a radio button group in a form that renders for all the skills in the skills table.
I'm using a JS query to create a data array (from the selected buttons in the radio button group) to feed to a Bulk Upsert with Primary Key (GUI).
When I access a employee record that hasn't had any skills assigned to it, I select a couple of buttons and press "Submit", I get the following error.
Primary key id is not unique in the supplied array. The following keys were duplicated: null -- (2 dupes)
id: (qry_Skillz_By_Employee.data.es_id[index]?qry_Skillz_By_Employee.data.es_id[index]:), is a syntax error
id: (qry_Skillz_By_Employee.data.es_id[index]?qry_Skillz_By_Employee.data.es_id[index]:''), yields Primary key id is not unique in the supplied array. The following keys were duplicated: -- (2 dupes)
id: (qry_Skillz_By_Employee.data.es_id[index]?qry_Skillz_By_Employee.data.es_id[index]:""), yields Primary key id is not unique in the supplied array. The following keys were duplicated: -- (2 dupes)
A quick and dirty solution would be setting the key to undefined like you were before, then looping over the array and running JSON.parse(JSON.stringify(item)) on each item in the array.
I'm not familiar enough with JSON to know what that would do? It appears to force the values into their string equivalents. How does this resolve the duplicate Primary Keys problem?
It turns out that there may be a bug with the way our DB connector is processing these upserts Can you do a quick test to see if the array contains only new rows (ie none have the id field) if the behavior is any different?
Hmm, yeah, this definitely looks like a bug. I assume that this ID column is an autoincrementing value, so you are unable to calculate and insert the correct id values
same issue here. normally if inserting into a database, we could have multiple NULL values in the primary key, and just let them autoincrement. So I think the simple solution here would be if retool could allow the query to run with multiple NULL values, instead of considering that an error @mark . Thank you!