79609520

Date: 2025-05-06 21:43:51
Score: 0.5
Natty:
Report link

Thanks! @kulatamicuda for hint.
I'm using liquibase with sprinboot, I made working using below setup -

  1. 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\
    
  2. 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>
    
  3. 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
    
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @for
  • Low reputation (0.5):
Posted by: drt