Update one row in the table, using liquibase

懵懂的女人 提交于 2021-01-20 18:47:46

问题


I was hoping if someone could verify if this is the correct syntax and correct way of populating the DB using liquibase? All, I want is to change value of a row in a table and I'm doing it like this:

<changeSet author="name" id="1231">
<update tableName="SomeTable">
    <column name="Properties" value="1" />
    <where>PROPERTYNAME = 'someNameOfThePropery"</where>
</update>
<changeSet>

All I want is to change one value in a row in some table. The above doesn't work, although application compiled and it didn't complain, but alas, the value wasn't changed.

Thank you


回答1:


Yes it is possible. See the below syntax:

<changeSet author="name" id="1231">
    <update catalogName="dbname"
            schemaName="public"
            tableName="SomeTable">
        <column name="Properties" type="varchar(255)"/>
        <where>PROPERTYNAME = 'someNameOfThePropery'</where>
    </update>
</changeSet>

More info at Liquibase Update




回答2:


The above answers are overly complicated, for most cases this is enough:

<changeSet author="name" id="123">
    <update tableName="SomeTable">
        <column name="PropertyToSet" value="1" />
        <where>otherProperty = 'otherPropertyValue'</where>
    </update>
</changeSet>

important to use single quotes ' and not double quotes " in the WHERE clause.




回答3:


The above post can be modified to correct format in this way. Inserted value="1" which is the expected result in the question of this post.

<changeSet author="name" id="1231">
    <update catalogName="dbname"
            schemaName="public"
            tableName="SomeTable">
        <column name="Properties" **value="1"** type="varchar(255)"/>
        <where>PROPERTYNAME = 'someNameOfThePropery'</where>
    </update>
</changeSet>


来源:https://stackoverflow.com/questions/16627627/update-one-row-in-the-table-using-liquibase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!