我正在使用数据库迁移Grails插件。但是当使用liquibase格式化的sql迁移时,运行dbm-update会导致我的某些sql出现致命错误。我收到这个错误:
liquibase : 'Change Set GraphFunctions.sql::graph_functions_initialize_1::<user> failed. Error: null'
java.lang.ArrayIndexOutOfBoundsException
当我运行代码时会发生这种情况:
--changeset <username>:graph_functions_initialize_1
CREATE OR REPLACE FUNCTION build_trcd(
IN new_parent_id bigint,
IN new_child_id bigint)
RETURNS TABLE(ancestor_id bigint, descendant_id bigint, paths bigint, cost bigint) AS '
SELECT
t1.ancestor_id AS ancestor_id,
t2.descendant_id AS descendant_id,
SUM(t1.paths*t2.paths)::bigint AS paths,
MIN(t1."cost"+t2."cost")+1::bigint AS "cost"
FROM db_set_membership_closure t1, db_set_membership_closure t2
WHERE t1.descendant_id=new_parent_id AND t2.ancestor_id=NEW_child_id
GROUP BY t1.ancestor_id, t2.descendant_id
UNION
SELECT
NEW_parent_id AS ancestor_id,
descendant_id AS descendant_id,
paths AS paths ,
(c."cost" + 1)::bigint AS "cost"
FROM db_set_membership_closure c
WHERE ancestor_id = NEW_child_id
UNION
SELECT
ancestor_id AS ancestor_id,
NEW_child_id AS descendant_id,
paths AS paths,
c."cost" + 1::bigint AS "cost"
FROM db_set_membership_closure c
WHERE descendant_id = NEW_parent_id
UNION VALUES (NEW_parent_id, NEW_child_id,1::bigint,1::bigint);
' LANGUAGE sql;
--rollback drop function build_trcd;
如果我不使用formatted-sql那么它运行正常。但是,如果我这样做,那么我无法通过Liquibase接口管理回滚。有没有人能够深入了解我可能会改变什么才能使其发挥作用?
答案 0 :(得分:6)
事实证明,包含函数声明的sql更改集已失败,因为它们在create语句的中间包含分号。要解决这些错误,我只需要将formatted-sql更改为不拆分语句:
--changeset <username>:graph_functions_initialize_1 splitStatements:false