Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions core/translate/upsert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,20 +407,8 @@ pub fn emit_upsert(
});
let num_cols = ctx.table.columns.len();
let current_start = program.alloc_registers(num_cols);
for (i, col) in ctx.table.columns.iter().enumerate() {
if col.is_rowid_alias() {
program.emit_insn(Insn::RowId {
cursor_id: ctx.cursor_id,
dest: current_start + i,
});
} else {
program.emit_insn(Insn::Column {
cursor_id: ctx.cursor_id,
column: i,
dest: current_start + i,
default: None,
});
}
for i in 0..num_cols {
program.emit_column_or_rowid(ctx.cursor_id, i, current_start + i);
}

// BEFORE for index maintenance / CDC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ addr opcode p1 p2 p3 p4 p5 comment
28 SeekRowid 1 1 49 0 if (r[1]!=cursor 1 for table t2.rowid) goto 49
29 RowId 1 15 0 0 r[15]=t2.rowid
30 Column 1 1 16 0 r[16]=t2.name
31 Column 1 2 17 0 r[17]=t2.counter
31 Column 1 2 17 0 0 r[17]=t2.counter
32 Copy 15 18 2 0 r[18]=r[15]
33 Copy 17 21 0 0 r[21]=r[17]
34 Integer 1 22 0 0 r[22]=1
Expand Down
14 changes: 14 additions & 0 deletions testing/sqltests/tests/upsert.sqltest
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ expect {
1|11|new
}

@cross-check-integrity
test upsert-do-update-reads-added-column-default-for-prealter-row {
CREATE TABLE t(id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO t VALUES(1, 'alice');
ALTER TABLE t ADD COLUMN score INTEGER DEFAULT 42;

INSERT INTO t VALUES(1, 'bob', 0)
ON CONFLICT(id) DO UPDATE SET score = score + 1;
SELECT * FROM t;
}
expect {
1|alice|43
}

@cross-check-integrity
test upsert-values-mixed-insert-update {
CREATE TABLE m (a UNIQUE, b);
Expand Down
Loading