Default expression does not evaluate with native inserts
mnpw opened this issue · 1 comments
mnpw commented
Hey, thanks for working on this crate. I've run into an issue where DEFAULT
columns are not getting set properly.
To reproduce the issue, you can follow these steps:
- Create test table
create table test (id UInt32, id_bump DEFAULT id+1) ENGINE = MergeTree() ORDER BY id;
- Insert values
// main.rs
#[derive(Row, Debug, Default)]
pub struct Test {
id: u32,
}
// glue code
#[tokio::main]
async fn main() {
// init client
let row = Test {
id: 1,
};
client
.insert_native_block("INSERT INTO test FORMAT native", vec![row])
.await
.unwrap();
}
On querying the table, I see that the default expression (id
+1) set for column id_bump
is not being honored. Any idea why this may be?
Observed:
SELECT *
FROM test
┌─id─┬─id_bump─┐
│ 1 │ 0 │
└────┴─────────┘
Expected:
SELECT *
FROM test
┌─id─┬─id_bump─┐
│ 1 │ 2 │
└────┴─────────┘
cc: @tekjar
Protryon commented
This error isn't about klickhouse
crate, but I believe you need to set the columns you want to insert explicitly for defaults to be honored.
INSERT INTO test (id) FORMAT native
Otherwise Clickhouse is going to assume you're inserting all columns, and maybe it's defaulting it out to zero during decoding since the column is missing.