0

I am trying to execute below sql method using liquibase in springboot, other than method it's possible to execute any sql queries.

Below query gets executed without error when it's executed in psql terminal which works fine as expected.

--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;

The error which gets thrown when above line executed through 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.*]
1
  • 3
    You will need to use splitStatements:false
    – user330315
    Commented Jul 8, 2020 at 8:30

1 Answer 1

1

I had to use that query in a separate liquibvase sql file without

--liquibase formatted sql

liquibase executed the file with raw id in databasechangelog table

Not the answer you're looking for? Browse other questions tagged or ask your own question.