Question

I am looking for an example on how to use the <whereparams></whereparams> which belongs to <update></update>, but I couldn't find anything (even in the official documentation).

any help is much appreciated.thanks.

Was it helpful?

Solution

An example usage is

<update tableName="updateTest">
        <column name="varcharColumn" value="new column 1 value"/>
        <column name="dateCol" valueDate="2008-01-01"/>
        <column name="intCol" valueNumeric="11"/>
        <where>id=:value</where>
        <whereParams>
            <param valueNumeric="134" />
        </whereParams>
</update>

where the :value statements in the <where> block is replaced with the values in the `param' blocks. If there are multiple :value statements they are replaced in order within the where clause.

However, looking at the code, it looks like the usage of whereParams is not well used or integrated. Perhaps I am missing where it is being picked up, but it may not even be working outside blob/clob updating.

Give it a try and see if it works for you, otherwise I'd say stick with the standard where block until support is improved.

OTHER TIPS

I support @nathan-voxland answer. Seems he is very good in liquibase.

But i want share one more where/whereParams example with additional ability (you can use whereParams block for field names also):

<where>:name=:value and :name=:value</where>
<whereParams>
    <param name="id" valueNumeric="21"/>
    <param name="name" value="bob"/>
</whereParams>

I believe my example do not need more explanations.

In response to Nathan's comment about lack of support for this feature, I can confirm that it is working well in version 3.3.2. When he commented liquibase was at version 3.1.1. Maybe support was improved somewhere between 3.1.1 and 3.3.2, but from a quick browse through the change log I don't see which version this would have been.

The docs at http://www.liquibase.org/documentation/changes/update.html are sparse, but basically the contains a SQL-like where clause. So if you would normally do something like

UPDATE cat.person SET address = NULL WHERE id=12; 

Then your changeset would look like this:

<changeSet author="liquibase-docs" id="update-example">
    <update catalogName="cat"
            schemaName="public"
            tableName="person">
        <column name="address" type="varchar(255)"/>
        <where>id=12</where>
    </update>
</changeSet>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top