Skip to content

After assigning table.data directly, INSERT stores duplicate keys and DELETE throws #2715

Closed

Description

@mathiasrw

When rows are put into a table with a PRIMARY KEY by assigning alasql.tables.t.data (a documented way to load data fast), the key index stays empty. UPDATE rebuilds it since #2341, but INSERT and DELETE do not:

alasql('CREATE TABLE pk1 (id INT PRIMARY KEY, v INT)');
alasql.tables.pk1.data = [{id: 1, v: 1}, {id: 2, v: 2}];

alasql('INSERT INTO pk1 VALUES (1, 99)');   // 1: a second row with id 1 is stored
alasql('DELETE FROM pk1 WHERE id = 1');     // Error: Something wrong with primary key index on table

Measured on develop (94ccf84). UNIQUE keys behave the same way.

Direction

Rebuild the key indexes in one place that INSERT, UPDATE and DELETE all pass through, when the data no longer matches the index (for example when table.data has been replaced), instead of in the UPDATE path only. A duplicate key that gets stored and a DELETE that throws are wrong results, so this can go into 4.x.

Related: #774, #2318, #2341.

Activity

  1. added this to the v4.x Focus milestone on Oct 20, 2026
  2. added a commit that references this issue on Nov 8, 2026
    8b249b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions