Clickhouse - add a new column with the default value being based off another column
Asked Answered
A

1

5

I have a table in Clickhouse, table1, with columns A and B. I want to alter this table to have a new column C. For the purpose of default values (future data will have a different approach) I want C to be filled in with data from A.

I know how to achieve this with a static default value, e.g. 0 but that is not what I'm trying to achieve here.

Apgar answered 15/9, 2021 at 15:46 Comment(0)
F
6

DEFAULT may accept expression not only static value:

ALTER TABLE table1 ADD COLUMN C String DEFAULT A
Flavescent answered 15/9, 2021 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.