fezu54
fezu54

Reputation: 217

Is there a replace function in liquibase?

Liquibase offers the update function which updates the whole value in the column. Is there also a way to just replace a part of the value? Or do I have to use plain sql statements for it?

The value in the column looks like this:

downtime = maintenanceTime + rampUpTime + repairTime;

when calling

<changeSet author="faf" id="29.10.19-16:34-001">
    <update tableName="PARAMETER">
        <column name="VALUE" type="varchar(64)" value="setupTime" />
        <where>VALUE LIKE '%rampUpTime%'</where>
    </update>
</changeSet>

it translates it to

UPDATE parameter set VALUE = 'setupTime'  where VALUE like '%rampUpTime%'

I'm searching for something similar which will be translated into

UPDATE parameter
SET VALUE = REPLACE(VALUE, 'rampUpTime', 'setupTime')
WHERE VALUE LIKE '%rampUpTime%';

Upvotes: 8

Views: 4605

Answers (1)

htshame
htshame

Reputation: 7330

Liquibase doesn't offer REPLACE, but it offers valueComputed attribute for an <update> tag.

I think the following should do the trick:

<changeSet author="faf" id="29.10.19-16:34-001">
    <update tableName="PARAMETER">
        <column name="VALUE" type="varchar(64)" valueComputed="REPLACE(VALUE, 'rampUpTime', 'setupTime')" />
        <where>VALUE LIKE '%rampUpTime%'</where>
    </update>
</changeSet>

Upvotes: 12

Related Questions