liquibase 中的 Postgres 删除函数显示错误
Postgres Dropping Function in liquibase shows error
我在 xml 文件中有 FUNCTION
,例如:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="1.0-procedures" author="api-manager">
<sql>
DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert;
</sql>
<createProcedure>
CREATE FUNCTION proc_api_consumer_audit_insert()
RETURNS TRIGGER AS $api_consumer_audit$
BEGIN
INSERT INTO api_consumer_audit(LOREM_IPSUM) VALUES(LOREM_IPSUM);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
</createProcedure>
<rollback>
DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert;
</rollback>
</changeSet>
</databaseChangeLog>
更新期间 liquibase 向我显示以下错误:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default-cli) on project api-manager: Error setting up or running Liquibase: Migration failed for change set db/dev/changelog/1.0/1.0-procedures.xml::1.0-procedures::api-manager:
[ERROR] Reason: liquibase.exception.DatabaseException: ERROR: syntax error at end of input
[ERROR] Pozycja: 55 [Failed SQL: DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1
我无法解决这个错误日志。我该如何修复?
要删除函数,您需要指定包含参数签名的函数。如果函数没有参数,则需要使用()
:
DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert();
这在 Postgres 10 中放宽了。如果函数没有重载(只有一个参数签名),您可以省略参数列表。因此,在 Postgres 10 中,您的语句无需更改即可工作
我在 xml 文件中有 FUNCTION
,例如:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="1.0-procedures" author="api-manager">
<sql>
DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert;
</sql>
<createProcedure>
CREATE FUNCTION proc_api_consumer_audit_insert()
RETURNS TRIGGER AS $api_consumer_audit$
BEGIN
INSERT INTO api_consumer_audit(LOREM_IPSUM) VALUES(LOREM_IPSUM);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
</createProcedure>
<rollback>
DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert;
</rollback>
</changeSet>
</databaseChangeLog>
更新期间 liquibase 向我显示以下错误:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default-cli) on project api-manager: Error setting up or running Liquibase: Migration failed for change set db/dev/changelog/1.0/1.0-procedures.xml::1.0-procedures::api-manager:
[ERROR] Reason: liquibase.exception.DatabaseException: ERROR: syntax error at end of input
[ERROR] Pozycja: 55 [Failed SQL: DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1
我无法解决这个错误日志。我该如何修复?
要删除函数,您需要指定包含参数签名的函数。如果函数没有参数,则需要使用()
:
DROP FUNCTION IF EXISTS proc_api_consumer_audit_insert();
这在 Postgres 10 中放宽了。如果函数没有重载(只有一个参数签名),您可以省略参数列表。因此,在 Postgres 10 中,您的语句无需更改即可工作