【问题标题】:Liquibase to execute postgres method through SpringbootLiquibase 通过 Springboot 执行 postgres 方法
【发布时间】:2020-07-08 07:26:27
【问题描述】:

我正在尝试在 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.*]

【问题讨论】:

  • 您需要使用splitStatements:false

标签: java postgresql spring-boot database-trigger liquibase-hibernate


【解决方案1】:

我必须在单独的 liquibvase sql 文件中使用该查询,而无需

--liquibase formatted sql

liquibase 在databasechangelog 表中使用原始ID 执行文件

【讨论】:

    猜你喜欢
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    相关资源
    最近更新 更多