java - Liquibase 通过 Springboot 执行 postgres 方法
问题描述
我正在尝试在springboot中使用liquibase执行下面的sql方法,除了可以执行任何sql查询的方法。
下面的查询在 psql 终端中执行时不会出错,可以正常工作。
--changeset aequalis:1565334092800-33
CREATE OR REPLACE FUNCTION process_document_history() RETURNS TRIGGER AS $document_history$
BEGIN
IF (TG_OP = 'DELETE') THEN
INSERT INTO document_history SELECT 'D', now(), OLD.*;
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO document_history SELECT 'U', now(), OLD.*;
RETURN OLD;
END IF;
RETURN NULL;
END;
$document_history$ LANGUAGE plpgsql;
通过 liquibase 执行上述行时引发的错误。
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]:
Invocation of init method failed; nested exception is liquibase.exception.MigrationFailedException:
Migration failed for change set db/changelog/changes/version/db.changelog.source-v3.sql::1565334092800-33::aequalis:
Reason: liquibase.exception.DatabaseException:
Unterminated dollar quote started at position 73 in SQL CREATE OR REPLACE FUNCTION process_document_history() RETURNS TRIGGER AS $document_history$
BEGIN
IF (TG_OP = 'DELETE') THEN
INSERT INTO document_history SELECT 'D', now(), OLD.*. Expected terminating $$ [Failed SQL: CREATE OR REPLACE FUNCTION process_document_history() RETURNS TRIGGER AS $document_history$
BEGIN
IF (TG_OP = 'DELETE') THEN
INSERT INTO document_history SELECT 'D', now(), OLD.*]
解决方案
我不得不在单独的 liquibvase sql 文件中使用该查询,而无需
--liquibase formatted sql
liquibase 使用 databasechangelog 表中的原始 id 执行文件
推荐阅读
- python - PyCharm 运行配置仅显示 python 测试。如何运行它定期运行?
- python - 如何将终端控制台上打印的输出存储到 Python 中的文本文件中
- ruby-on-rails - 让 CoinMarketCap API 与 Ruby on Rails 2020 一起使用?
- docker - Docker Image:如何添加 Maven 依赖项以供离线使用?
- python - 使用 Python 将多列中的日期和时间转换为一个日期时间对象
- javascript - 我收到此错误解析错误:语法错误,意外'$s'(T_VARIABLE)
- javascript - 为什么在 action call inn 组件期间会出现“Actions must be plain objects”。- 错误?
- javascript - 如何在 cp-react-tree-table 中直接使用 api 响应
- typescript - 如何从两种类型中选择共同的属性?
- server - 云计算机生产模式下的最小机器数