簡體   English   中英

Liquibase 通過 Springboot 執行 postgres 方法

[英]Liquibase to execute postgres method through Springboot

我正在嘗試在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 執行文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM