Incorrect generation of changelog in Liquibase - No function matches… You might need to add explicit type casts.(liquibase + spring.boot)

I used the generate the command - changeLogcommand, to upload the data, and use the resulting file as a changelog.

liquibase generateChangeLog

I use PostgreSql 11.x

  • db.changelog-master.xml
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <include file="db/changelog/xml/db/changelog-1.xml"/>

</databaseChangeLog>

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
    <changeSet author="IT (generated)" id="1609684188168-1">
        <createTable remarks="Aircrafts (internal data)" tableName="aircrafts_data">
            <column name="aircraft_code" remarks="Aircraft code, IATA" type="CHAR(3)">
                <constraints nullable="false" primaryKey="true" primaryKeyName="aircrafts_pkey"/>
            </column>
            <column name="model" remarks="Aircraft model" type="JSONB">
                <constraints nullable="false"/>
            </column>
            <column name="range" remarks="Maximal flying distance, km" type="INTEGER">
                <constraints nullable="false"/>
            </column>
        </createTable>
    </changeSet>
    <changeSet author="IT (generated)" id="1609684188168-2">

....

    <changeSet author="IT (generated)" id="1609684188168-9">
        <createView fullDefinition="false" remarks="Aircrafts" viewName="aircrafts">SELECT ml.aircraft_code,
            (ml.model -&gt;&gt; lang()) AS model,
            ml.range
            FROM aircrafts_data ml;</createView>
    </changeSet>

...
  • pom.xml
 <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>

enter image description here

Then I would like to apply the resulting file to the created project. But an error appears on startup.

Caused by: liquibase. exception.Migration Failed Exception: migration
failed for dB/change set / in XML format/dB / change-1. XML module::
1609684188168-9: yes (automatically): Reason: liquibase. exception.
DatabaseException: ERROR: the lang () function does not exist Hint: No
function matches the specified name and argument types. You may need
to add explicit type casts. Position: 84 [not in SQL: (0) creating a
public view.aircraft, how to select ml. aircraft_code, (ml. model - >

lang()) as the ml. range model From aircraft_data ml;]

  • lang
create function lang() returns text
    stable
    language plpgsql
as
$$
BEGIN
  RETURN current_setting('bookings.lang');
EXCEPTION
  WHEN undefined_object THEN
    RETURN NULL;
END;
$$;

alter function lang() owner to postgres;

As I understand it, the generator could not also transfer the function to changelog.xml, as well as views.

When I used that

  • liquibase.properties
diffTypes:catalog,tables,functions,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints,data,storedprocedure,triggers,sequences

I have got the errors:

[2021-01-03 18:51:02] SEVERE [liquibase.integration] Unexpected error
running Liquibase: Java heap space java.lang.OutOfMemoryError: Java
heap space
at java.base/java.lang.StringUTF16.compress(StringUTF16.java:160)
at java.base/java.lang.String.(String.java:3214)
at java.base/java.lang.String.(String.java:276)
at org.postgresql.core.OptimizedUTF8Encoder.charDecode(OptimizedUTF8Encoder.java:71)
at org.postgresql.core.ByteOptimizedUTF8Encoder.decode(ByteOptimizedUTF8Encoder.java:27)
at org.postgresql.core.Encoding.decode(Encoding.java:252)
at org.postgresql.jdbc.PgResultSet.getString(PgResultSet.java:1910)
at org.postgresql.jdbc.PgResultSet.internalGetObject(PgResultSet.java:197)
at org.postgresql.jdbc.PgResultSet.getObject(PgResultSet.java:2577)
at liquibase.util.JdbcUtils.getResultSetValue(JdbcUtils.java:80)
at liquibase.diff.output.changelog.core.MissingDataChangeGenerator.fixMissing(MissingDataChangeGenerator.java:92)
at liquibase.diff.output.changelog.ChangeGeneratorChain.fixMissing(ChangeGeneratorChain.java:48)
at liquibase.diff.output.changelog.ChangeGeneratorFactory.fixMissing(ChangeGeneratorFactory.java:95)
at liquibase.diff.output.changelog.DiffToChangeLog.generateChangeSets(DiffToChangeLog.java:302)
at liquibase.diff.output.changelog.DiffToChangeLog.printNew(DiffToChangeLog.java:226)
at liquibase.diff.output.changelog.DiffToChangeLog$1.run(DiffToChangeLog.java:133)
at liquibase.Scope.lambda$child$0(Scope.java:160)
at liquibase.Scope$$Lambda$42/0x00000008000ecc40.run(Unknown Source)
at liquibase.Scope.child(Scope.java:169)
at liquibase.Scope.child(Scope.java:159)
at liquibase.Scope.child(Scope.java:138)
at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:127)
at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog.java:85)
at liquibase.command.core.GenerateChangeLogCommand.run(GenerateChangeLogCommand.java:74)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:19)
at liquibase.integration.commandline.CommandLineUtils.doGenerateChangeLog(CommandLineUtils.java:249)
at liquibase.integration.commandline.Main.doMigration(Main.java:1519)
at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:361)
at liquibase.integration.commandline.Main$1$$Lambda$41/0x00000008000ec840.run(Unknown
Source)
at liquibase.Scope.lambda$child$0(Scope.java:160)
at liquibase.Scope$$Lambda$42/0x00000008000ecc40.run(Unknown Source)
at liquibase.Scope.child(Scope.java:169)

Then I removed the - data type. The file was generated without errors (data -had to be deleted. The error was possible due to the fact that it was necessary to check a large amount of data).

But I still don’t see the - lang() function there.

As I understand it, there should be something like: create function

How can I configure the generation to avoid such errors in the future, and how can I fix it manually ?

Hi @sky-alex ,

What version of Liquibase are you using? Also are you using Community or Pro?

Thanks for all the info you included!

-Ronak