Thanks! @kulatamicuda for hint.
I'm using liquibase with sprinboot, I made working using below setup -
I have sql in fn_count.sql
CREATE OR REPLACE FUNCTION totalRecords ()
RETURNS integer AS $total$
declare
total integer;
BEGIN
SELECT count(*) into total FROM COMPANY;
RETURN total;
END;
$total$ LANGUAGE plpgsql\
fn_count.xml - here important part is - endDelimiter="\"
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<changeSet id="2025050605" author="AUTHOR">
<sqlFile path="sql-scripts/fn_count.sql"
relativeToChangelogFile="true"
endDelimiter="\"
splitStatements="true"
stripComments="true"/>
</changeSet>
</databaseChangeLog>
db.changelog-master.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
<include file="fn_count.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
File structure looks like this -
src/main/resources/
├── db/
│ ├── changelog/
│ │ └── fn_count.xml, db.changelog-master.xml
│ │ └── sql-scripts/
│ │ └── fn_count.sql