'Two conditions in where tag of Liquibase
I want to add two conditions in where tag of liquibase and exception is thrown:
Reason: liquibase.exception.DatabaseException: Unknown column 'uid' in 'where clause' [Failed SQL: UPDATE kw.media_file SET created = '1586352959' WHERE id=1 AND uid='admin']
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
Here is the changeLog:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"
logicalFilePath="src/main/resources/db/update.xml">
<changeSet author="author" id="20200409-update">
<update tableName="media_file">
<column name="last_modified" type="int(11)" value="1586438425"/>
<where>id=1 AND uid='admin'</where>
</update>
</changeSet>
Equivalent sql statement is here:
update person set created = 1586352959 where id = 2 and uid='admin';
When I run the SQL statement, the column is updated but no luck with liquibase.
Solution 1:[1]
As stated in the comment - the error and the changeSet you've provided don't match each other.
The error is that column uid
is not found in table media_file
Your changeSet is synthetically correct, and you can provide multiple conditions in one <where>
tag.
Based on the SQL statement you've provided
update person set created = 1586352959 where id = 2 and uid='admin';
So I can assume the changeSet you're looking for may look something like:
<changeSet author="foo" id="bar">
<update tableName="person">
<column name="created" type="int(11)" value="1586438425"/>
<where>id = 2 AND uid = 'admin'</where>
</update>
</changeSet>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |