Skip to content

Match INSERT SELECT columns by position when no name matches to close #2760 - #3007

Open
mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2760-insert-select-by-position
Open

mateuscmtropical wants to merge 1 commit into
AlaSQL:developfrom
mateuscmtropical:fix-2760-insert-select-by-position

Conversation

@mateuscmtropical

Copy link
Copy Markdown
Contributor

Closes #2760

What was wrong

INSERT INTO t SELECT matches the selected columns to the target by name. When no selected name is a column of the target, every row came out as {}. The column list in INSERT INTO f (x, y) SELECT ... was not used at all on this path.

What changed

New helper matchInsertColumnsByPosition() in 70insert.js. When none of the selected names is a target column, it maps the selected columns to the target columns by position. The target columns are the column list if there is one, and else the table columns. The selected names come from the compiled SELECT, so the select list order is kept. When at least one name matches, nothing changes, as the issue asks.

Tests

test/test2760.js covers the queries from the issue: SELECT * into other names, a column list (also in another order), computed columns, the primary key case, and the two by-name cases that stay the same. The first four fail on develop.

yarn test-only gives 2556 pass. The only failures are the 5 Test 418 cases that load files from the internet.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

INSERT INTO t SELECT gives empty rows when no selected column name is a column of the table

2 participants