Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a replace function in liquibase?

Tags:

java

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%';
like image 479
fezu54 Avatar asked Mar 04 '23 05:03

fezu54


1 Answers

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>
like image 175
htshame Avatar answered Mar 11 '23 22:03

htshame