liquibase update data based on existing column

2.3k views Asked by At

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
1

There are 1 answers

0
Kyle Burkett On

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.