Skip to content

Commit

Permalink
Fix duplicate cast in insert (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw authored Oct 5, 2023
1 parent 0ad82e7 commit ce2d04c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test command
```sql
create table t1 (a int, b int);

insert into t1 (a, b) values (1, 1), (5, 3), (5, 2);
insert into t1 (a, b) values (1, 1), (5, 3), (6, 2);

update t1 set a = 0 where b > 1;

Expand Down
4 changes: 3 additions & 1 deletion src/binder/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ impl<S: Storage> Binder<S> {
}
ScalarExpression::Unary { expr, op, .. } => {
if let ScalarExpression::Constant(value) = expr.as_ref() {
row.push(Arc::new(unary_op(value, op)?))
row.push(Arc::new(
unary_op(value, op)?.cast(columns[i].datatype())?,
))
} else {
unreachable!()
}
Expand Down
3 changes: 1 addition & 2 deletions src/execution/executor/dml/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ impl Insert {
let mut tuple_map = HashMap::new();
for (i, value) in values.into_iter().enumerate() {
let col = &columns[i];
let cast_val = DataValue::clone(&value).cast(&col.datatype())?;

if let Some(col_id) = col.id {
tuple_map.insert(col_id, Arc::new(cast_val));
tuple_map.insert(col_id, value);
}
}
let primary_col_id = primary_key_index.get_or_insert_with(|| {
Expand Down

0 comments on commit ce2d04c

Please sign in to comment.