Skip to content

INSERT INTO t SELECT matches columns by position in the sqlite dialect #2773

Open

Description

@mathiasrw

In the sqlite dialect, INSERT INTO t SELECT ... without a column list should match the selected columns to the table's columns by position, as SQL and SQLite do. The alasql dialect keeps matching by name.

Split from #2760, which fixes the case that is wrong today (no selected name is a column of the table: empty rows) in 4.x.

alasql('CREATE TABLE s (a INT)');
alasql('CREATE TABLE d (b INT, a INT)');
alasql('INSERT INTO s VALUES (7)');
alasql('INSERT INTO d SELECT * FROM s');
alasql('SELECT * FROM d');
// alasql dialect (today and after 5.0): [{a: 7}]
// sqlite dialect: [{b: 7, a: null}], as SQLite

Why not in the alasql dialect

Matching by name is consistent and fits rows as objects. Code that copies rows between tables with the same column names in another order, or from a source with extra columns, relies on it. Changing the default would put data in other columns without an error. The rules of the alasql dialect (context/strategic-direction.md): where v4 is consistent, keep it.

The sqlite dialect may move closer to SQLite in a minor version, so this is not a breaking change.

Related: #2760.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions