'Liquibase: PSQLException: Unterminated dollar using SQL Changelog
I have two functions that i wanted to add to my DB using liquibase. First one is:
--changeset polos:001_9
create or replace function xml_attribute_element(attribute_name varchar(255), source numeric)
returns xml as $body$
declare
begin
return xml_attribute_element(attribute_name, source::text);
end;
$body$
language plpgsql immutable;
I got Unterminated dollar-quoted string at or near "$BODY$ error with it and used the way described here https://forum.liquibase.org/t/unterminated-dollar-quote-started/4553 to fix it. Now it works and looks like:
--changeset polos:001_9
create or replace function xml_attribute_element(attribute_name varchar(255), source numeric)
returns xml as '
declare
begin
return xml_attribute_element(attribute_name, source::text);
end;
'
language plpgsql immutable;
The second function is:
--changeset polos:001_10
create or replace function xml_text_escape(source text)
returns text as $body$
declare
sa varchar[] := array['&', '<', '>', '"'];
da varchar[] := array['&', '<', '>', '"'];
t text := source;
begin
FOR i IN 1..array_length(sa, 1) LOOP
t := replace(t, sa[i], da[i]);
END LOOP;
return t;
end;
$body$
language plpgsql immutable;
I cant fix it by replacing $body$ with ' because it has $ inside its body, so im getting same Unterminated dollar quote but in another place.
Are there any ways to fix it?
Here is a playground: https://www.db-fiddle.com/f/kpmP1y7U4UvUhbgahuQrQc/1
Solution 1:[1]
Answer based on @a_horse_with_no_name comment: splitStatements=false can be used to solve this issue.
Declaration for SQL changelog: --changeset name:id splitStatements:false
Additionally:
- If you have several functions to declare you have to do it in separate changesets;
- You may do it without replacing '$body$' with
'when usingsplitStatements=false.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Polos |
