Liquibase 在索引中使用添加的功能不适用于 postgres 数据库
Liquibase use added function in index does not work for postgres database
我在 liquibase 中使用以下变更集向现有数据库添加功能
<changeSet author="me" id="2">
<sqlFile encoding="UTF-8"
path="add_function_my_timestamp.sql"
relativeToChangelogFile="true"
splitStatements="false"
stripComments="false"
endDelimiter=";"/>
sql文件(add_function_my_timestamp.sql)的内容是
CREATE FUNCTION public.my_timestamp(some_time timestamp without time zone) RETURNS timestamp with time zone
LANGUAGE sql IMMUTABLE
AS $_$
select date_trunc('day', cast( AT TIME ZONE 'Europe/Berlin' as date))
$_$;
Liquibase 告诉我迁移成功
SQL in file add_function_my_timestamp.sql executed
ChangeSet update_20220223::2::me ran successfully in 13ms
但是当我在创建索引时尝试在另一个变更集中使用此变更集创建的函数时
<changeSet author="me" id="3">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*)
from information_schema.constraint_column_usage
where table_name = 'myEntity' and constraint_name = 'description_day_timestamp_unique'
</sqlCheck>
</preConditions>
<sql>
CREATE UNIQUE INDEX description_day_timestamp_unique ON myEntity."myProperty" USING btree (description, public.my_timestamp(insertdate));
</sql>
然后我得到错误
Reason: liquibase.exception.DatabaseException: ERROR: function
public.my_timestamp(timestamp with time zone) does not exist
Hint: No function matches the given name and argument types. You
might need to add explicit type casts.
我发现错误。参数类型错误
我在 liquibase 中使用以下变更集向现有数据库添加功能
<changeSet author="me" id="2">
<sqlFile encoding="UTF-8"
path="add_function_my_timestamp.sql"
relativeToChangelogFile="true"
splitStatements="false"
stripComments="false"
endDelimiter=";"/>
sql文件(add_function_my_timestamp.sql)的内容是
CREATE FUNCTION public.my_timestamp(some_time timestamp without time zone) RETURNS timestamp with time zone
LANGUAGE sql IMMUTABLE
AS $_$
select date_trunc('day', cast( AT TIME ZONE 'Europe/Berlin' as date))
$_$;
Liquibase 告诉我迁移成功
SQL in file add_function_my_timestamp.sql executed
ChangeSet update_20220223::2::me ran successfully in 13ms
但是当我在创建索引时尝试在另一个变更集中使用此变更集创建的函数时
<changeSet author="me" id="3">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select count(*)
from information_schema.constraint_column_usage
where table_name = 'myEntity' and constraint_name = 'description_day_timestamp_unique'
</sqlCheck>
</preConditions>
<sql>
CREATE UNIQUE INDEX description_day_timestamp_unique ON myEntity."myProperty" USING btree (description, public.my_timestamp(insertdate));
</sql>
然后我得到错误
Reason: liquibase.exception.DatabaseException: ERROR: function
public.my_timestamp(timestamp with time zone) does not exist
Hint: No function matches the given name and argument types. You
might need to add explicit type casts.
我发现错误。参数类型错误