Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EndDelimiter "$$" cannot be correctly parsed in SQL of a change set after upgrading Liquibase to 4.29.2 #6403

Open
1 of 2 tasks
wangweiao opened this issue Oct 7, 2024 · 4 comments

Comments

@wangweiao
Copy link

wangweiao commented Oct 7, 2024

Search first

  • I searched and no similar issues were found

Description

We are deploying SQL and PL/pgSQL scripts on an PostgreSQL Database via Liquibase. We use "$$" as endDelimiter in our code.

Since 4.29.2 this is some kind of broken. Now endDelimiter "$$" cannot be correctly parsed in SQL of a change set after upgrading Liquibase.

Steps To Reproduce

<sql endDelimiter="$$">
            create function foo() returns trigger AS $$
            begin
            ...
            end;
            $$ language plpgsql;

            create trigger
            ... 
            execute procedure foo();
</sql>

Error caused:

Caused by: liquibase.exception.MigrationFailedException: Migration failed    
Reason: liquibase.exception.DatabaseException
ERROR: syntax error at end of input [Failed SQL: (0) create function A() returns trigger AS] 

Expected/Desired Behavior

"$$" should be parsed as endDelimiter as before.

Liquibase Version

4.29.2

Database Vendor & Version

PostgreSQL 42.6.1

Liquibase Integration

No response

Liquibase Extensions

No response

OS and/or Infrastructure Type/Provider

No response

Additional Context

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR (Thank you!)
@wangweiao wangweiao changed the title EndDelimiter "$$" cannot be correctly parsed in SQL of a change set after upgrading Liquibase to 4.29.2. EndDelimiter "$$" cannot be correctly parsed in SQL of a change set after upgrading Liquibase to 4.29.2 Oct 7, 2024
@lbadam lbadam added the TypeBug label Oct 7, 2024
@tati-qalified
Copy link
Contributor

Hi @wangweiao, I have two questions in order to better understand this issue:

  1. What Liquibase version were you using before updating to 4.29.2?
  2. Would you be able to run liquibase update-sql and send us the resulting code? Feel free to remove the procedure's logic if it contains sensitive information.

Thank you,
Tatiana

@wangweiao
Copy link
Author

Hi @tati-qalified ,

  1. We were previously using Liquibase version 4.27.0 before updating to 4.29.2.
  2. Here is the result after running liquibase update-sql:
create function foo() returns trigger AS;
begin
...
end;
language plpgsql;

create trigger 
...
execute procedure foo();

Best regards,
Weiao

@tati-qalified tati-qalified added this to the Epic: End Delimiters milestone Oct 16, 2024
@tati-qalified
Copy link
Contributor

@wangweiao it seems that Liquibase is interpreting the $$ that mark the beginning and ending of the function, as end delimiters. You can see this change in the generated code.

For 4.27.0:

create function foo() returns trigger AS 
            $$
            begin
            ...
            end;
            $$ language plpgsql;

For 4.28.0 through 4.29.2:

create function foo2() returns trigger AS;

begin
            
            ...
            end;

language plpgsql;

So now it's separating the "create" sentence from the function definition. This happens since Liquibase version 4.28.0.

We'll be looking into this. If you'd be willing to submit a PR to propose a fix, feel free to do so!

Thank you,
Tatiana

@tati-qalified tati-qalified moved this from New to Candidate in Liquibase Open Source Oct 17, 2024
@MalloD12 MalloD12 self-assigned this Nov 5, 2024
@MalloD12 MalloD12 moved this from Foundation Team Tickets to Development in Liquibase Open Source Nov 5, 2024
@MalloD12
Copy link
Collaborator

MalloD12 commented Nov 8, 2024

Hi Wang (@wangweiao),

If I'm not wrong this is working as expected. Recently, some endDelimiter issues have been fixed and this reported case seems to be behaving correctly. If we use $$ this is going to split your function in multiple statements like the ones below:

Statement 1:

create function foo() returns trigger AS 

Statement 2:

begin
...
end;

Statement 3:

language plpgsql;

create trigger
... 
execute procedure foo();

Then execution of statement one is not a valid SQL to create a function, so the returned error seems okay to us.

Thanks,
Daniel.

@MalloD12 MalloD12 moved this from Development to In Discussion in Liquibase Open Source Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Discussion
Development

No branches or pull requests

4 participants