'liquibase update data based on existing column
Here, I am new to liquibase and I have a scenario where I need to add a new column to the existing table and have the value of this column based on existing column. However I was able to add column but I couldn't find a way to set default value for this column.
consider I have a table called table_1
| id | col1 | col2 |
|---|---|---|
| 1 | 11 | 22 |
| 2 | 12 | 33 |
| 3 | 13 | 44 |
Now I want to add column col3 in the above table and have value of this column same as col2. I am expecting output something like
| id | col1 | col2 | col3 |
|---|---|---|---|
| 1 | 11 | 22 | 22 |
| 2 | 12 | 33 | 33 |
| 3 | 13 | 44 | 44 |
Solution 1:[1]
You've marked liquibase SQL, are you using SQL as the preferred language in your changelog?
I think if you are, a SQL statement might work:
-- liquibase formatted sql
-- changeset user1:1651490946175-1
UPDATE TABLENAME SET col3 = col2;
Otherwise, you could use similar syntax in json, yaml.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kyle Burkett |
