You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Updating a table with PK and direct data assignment throws an error #1989
// pseudo-code
a = new alasql.Database();
a.exec("create table with no pk");
a.tables.table.data = [ some data ] ;
a.exec("update table");
// update runs correctly
Updating data with pk works fine if using insert statements:
// pseudo-code
a = new alasql.Database();
a.exec("create table with no pk");
a.exec("insert some data");
a.exec("update table");
// update runs correctly
Updating data with pk and direct assignment fails
// pseudo-code
a = new alasql.Database();
a.exec("create table with pk");
a.tables.table.data = [ some data ] ;
a.exec("update table");
// update throws an error
Hello @mathiasrw , I did a little debugging on this issue.
While debugging, I noticed the following behavior when we assign data directly:
It replaces the entire data in the table variable.
It does not assign the uniqs attribute, which is required when performing table.update.
Below is an example of the table data when using exec followed by directly assigning data.
I believe that if the assignment of data is a mandatory feature, a setter should be provided. For instance, when creating a table object, it could be added as follows:
Object.defineProperty(table,'data',{set(newValue){// iterate through newValue// table.insert(...)value=newValue;}});
Activity
IrwantoCia commentedon Dec 17, 2024
Hello @mathiasrw , I did a little debugging on this issue.
While debugging, I noticed the following behavior when we assign
datadirectly:It replaces the entire
datain thetablevariable.It does not assign the
uniqsattribute, which is required when performingtable.update.Below is an example of the
tabledata when usingexecfollowed by directly assigningdata.As we can see example_id 1 is inserted into
uniqsanddata, but after assigntable.data, thedatagot replaced and theuniqsis not updated.ilyboc commentedon Jan 6, 2025
I believe that if the assignment of data is a mandatory feature, a setter should be provided. For instance, when creating a table object, it could be added as follows:
Should I create a PR?
Fix UPDATE on tables with PK when data is directly assigned to close A…
mathiasrw commentedon Dec 13, 2025
Fix released as part of v4.12.0
@tevanburen if you could confirm its working for you now that would be awesome.
tevanburen commentedon Dec 29, 2025
Just tested the newest version with the same jsfiddle code linked above, and it works. Thank you