is it possible to update an existing row in DB, using liquibase?

user2187935 picture user2187935 · May 20, 2013 · Viewed 17.3k times · Source

Tried to find an answer to this question, but couldn't.

So, for example I have this table:

TABLE:

col1 | col2
123       0
124       1

and I want to change col2 value to 1 and this is how I'm trying to do it:

<changeSet author="myName" id="7799">
        <sql>
        UPDATE TABLENAME;
        SET COL1='1' WHERE col1='123';
        </sql>
</changeSet>

Alas, it doesn't work. So, I was wondering if it is even possible to do that with liquibase? Since, most tags in the documentation have to do with creating table, adding columns etc.

Answer

Mohammad Nadeem picture Mohammad Nadeem · May 29, 2013

You can use the following liquibase syntax to update:

<changeSet author="myname" id="7799">
    <update catalogName="dbname"
            schemaName="public"
            tableName="TABLENAME">
        <column name="COL1" value='1' type="varchar(50)"/>
        <where>col1='123'</where>
    </update>
</changeSet>

For the other options available please check Liquibase Update