Skip to content

Commit ce2d04c

Browse files
authored
Fix duplicate cast in insert (#78)
1 parent 0ad82e7 commit ce2d04c

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test command
1919
```sql
2020
create table t1 (a int, b int);
2121

22-
insert into t1 (a, b) values (1, 1), (5, 3), (5, 2);
22+
insert into t1 (a, b) values (1, 1), (5, 3), (6, 2);
2323

2424
update t1 set a = 0 where b > 1;
2525

src/binder/insert.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ impl<S: Storage> Binder<S> {
5959
}
6060
ScalarExpression::Unary { expr, op, .. } => {
6161
if let ScalarExpression::Constant(value) = expr.as_ref() {
62-
row.push(Arc::new(unary_op(value, op)?))
62+
row.push(Arc::new(
63+
unary_op(value, op)?.cast(columns[i].datatype())?,
64+
))
6365
} else {
6466
unreachable!()
6567
}

src/execution/executor/dml/insert.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ impl Insert {
6363
let mut tuple_map = HashMap::new();
6464
for (i, value) in values.into_iter().enumerate() {
6565
let col = &columns[i];
66-
let cast_val = DataValue::clone(&value).cast(&col.datatype())?;
6766

6867
if let Some(col_id) = col.id {
69-
tuple_map.insert(col_id, Arc::new(cast_val));
68+
tuple_map.insert(col_id, value);
7069
}
7170
}
7271
let primary_col_id = primary_key_index.get_or_insert_with(|| {

0 commit comments

Comments
 (0)