Search code examples
liquibase

liquibase update where with LIKE clause


I want to add LIKE clause to liquibase update. Have done something like that, but it seems to be not working properly:

    <changeSet id="LoremIpsum" author="JohnDoe">
    <update tableName="table_for_John_Doe">
        <column name="id" value="000001"/>
        <where>
            from LIKE :first OR
            from LIKE :second OR
            to LIKE :first OR
            to LIKE :second
        </where>
        <whereParams>
            <param name="first" value="TEST1"/>
            <param name="second" value="TEST2"/>
        </whereParams>
    </update>
</changeSet>

I tried adding '' but again no expected results. If it should be working so maybe I have made a mistake somewhere else.

Should I write native sql query instead?


Solution

  • I think the problem is that you are using the whereParams incorrectly.
    Have a look here: LiquiBase : How to use <whereparams> inside an <update>?

    For a table like this:

    id name column_to_update
    1 AA
    2 AB
    3 BA
    3 CA

    The change set, for example to update all rows, where name starts with A or C, should look like this:

        <changeSet id="LoremIpsum" author="JohnDoe">
            <update tableName="table_for_John_Doe">
                <column name="column_to_update" value="000001"/>
                <where>
                     :name LIKE :value or
                     :name LIKE :value 
                </where>
                <whereParams>
                    <param name="name" value="A%"/>
                    <param name="name" value="C%"/>
                </whereParams>
            </update>
        </changeSet>