I have a table with a column A. I am creating a new column B. B will have the same data as column A. How do I replicate the column in Liquibase? Is there some expression I can write to do the replication?
Select the row or column that you want to move or copy. In the cell, click where you want to paste the characters, or double-click another cell to move or copy the data. or press Ctrl+V. Press ENTER.
UPDATE table SET columnB = columnA; This will update every row. This will also work if you want to transfer old value to other column and update the first one: UPDATE table SET columnA = 'new value', columnB = columnA . Like other answer says - don't forget the WHERE clause to update only what's needed.
In such a case, you can use the following UPDATE statement syntax to update column from one table, based on value of another table. UPDATE first_table, second_table SET first_table. column1 = second_table. column2 WHERE first_table.id = second_table.
Create a new changeset where you add a new column, and then update column B
using the <sql>
tag:
<changeSet author="yourName" id="example">
<addColumn catalogName="db"
schemaName="public"
tableName="yourTable">
<!-- replace varchar(255) with the actual type of column A -->
<column name="B" type="varchar(255)"/>
</addColumn>
<sql>UPDATE yourTable SET B = A</sql>
</changeSet>
this is possible too:
<changeSet id="1" author="your_name">
<addColumn tableName="your_table">
<column name="b" type="varchar(255)"/>
</addColumn>
</changeSet>
<changeSet id="2" author="your_name">
<update tableName="your_table">
<column name="b" valueComputed="a"/>
</update>
</changeSet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With