sql - Liquibase的where标签中的两个条件
问题描述
我想在引发 liquibase 和异常标记的位置添加两个条件:
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)
这是更改日志:
<?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>
等效的sql语句在这里:
update person set created = 1586352959 where id = 2 and uid='admin';
当我运行 SQL 语句时,列已更新,但 liquibase 没有运气。感谢。
解决方案
如评论中所述 - 您提供的错误和 changeSet 不匹配。
错误是uid
在表中找不到该列media_file
您的 changeSet 综合正确,您可以在一个<where>
标签中提供多个条件。
根据您提供的 SQL 语句
更新人员集 created = 1586352959 其中 id = 2 和 uid='admin';
所以我可以假设你正在寻找的 changeSet 可能看起来像:
<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>
推荐阅读
- .net - 带有 .NET Core 3.0 的 VSTO
- ios - What is the alternative to WebIntent on iOS in Ionic 4?
- sql - 我想加入两个表并获取 10 秒间隔内的记录
- python - 使用服务帐户进行 Google API 身份验证
- node.js - How to warmup a serverless lambda with child routes in nodejs
- c# - C# Math.Net - 如何正确设置 Fit.Curve 的参数
- mysql - SQL - 过滤的命名条件
- powershell - Powershell 2.0 对文件中的列进行计数
- syncfusion - 在我的项目中使用同步融合没有获取图形属性
- flutter - 在 Flutter 项目中使用 Material Design 图标