Postgresql错误类型"&引用;不存在

Postgresql错误类型"&引用;不存在,postgresql,docker,dockerfile,postgresql-9.4,Postgresql,Docker,Dockerfile,Postgresql 9.4,我得到这个错误: Caused by: org.postgresql.util.PSQLException: ERROR: type "tool_parse_numbers_record" does not exist Where: compilation of PL/pgSQL function "tool_parse_numbers" near line 2 我正在还原docker容器中的数据库,如下所示: FROM postgres:9.4 EN

我得到这个错误:

    Caused by: org.postgresql.util.PSQLException: ERROR: type 
    "tool_parse_numbers_record" does not exist
    Where: compilation of PL/pgSQL function "tool_parse_numbers" near line 2
我正在还原docker容器中的数据库,如下所示:

    FROM postgres:9.4
    ENV POSTGRES_USER iwb
    ENV POSTGRES_PASSWORD 1907
    ENV POSTGRES_DB iwb

    ADD ./1_schema.sql /docker-entrypoint-initdb.d/
    ADD ./2_data.sql /docker-entrypoint-initdb.d/
下面是schema.sql文件中的类型定义:

    CREATE TYPE tool_parse_numbers_record AS (
     satir character varying(4000)
    );
下面是schema.sql中函数定义的顶部:

    CREATE FUNCTION tool_parse_numbers(pstr text, pdelimeter text DEFAULT 
    '|'::text) RETURNS SETOF tool_parse_numbers_record
    LANGUAGE plpgsql SECURITY DEFINER
    AS $$
    DECLARE
这就是数据库恢复的方式:

    CREATE FUNCTION tool_parse_numbers(pstr text, pdelimeter text DEFAULT 
    '|'::text) RETURNS SETOF tool_parse_numbers_record
    LANGUAGE plpgsql SECURITY DEFINER
    AS $BODY$
    DECLARE
编辑: 我将dockerfile更改为在函数之前创建类型:

    ADD ./1_type.sql /docker-entrypoint-initdb.d/
    ADD ./2_table.sql /docker-entrypoint-initdb.d/
    ADD ./3_func.sql /docker-entrypoint-initdb.d/
    ADD ./4_rest_table.sql /docker-entrypoint-initdb.d/
    ADD ./5_data.sql /docker-entrypoint-initdb.d/

我怎么修理它

您确定类型是在函数之前创建的吗

类型是否与函数在同一架构中创建?(是否未在使用的sql文件中的某个位置设置搜索路径?)

$$和$BODY$以“dolar quoted string”开头,以相同($$或$BODY$)结尾。您可以使用任意字符(或任意字符)而不是正文,它只允许在字符串中写入$$,“,等等,而不会出现问题。
为什么postgres使用$BODY$而不是$ILOVEBEER$还不清楚。

当我将数据库提取到schema.sql文件时,所有者被设置为postgres:

    ALTER FUNCTION iwb.tool_parse_numbers(pstr text, pdelimeter text) OWNER TO postgres; 
所以我将所有者改为iwb,因为docker文件中就是这样

    ENV POSTGRES_USER iwb

它成功了!

$$
$BODY$
之间没有区别-这不是您出错的原因。显然,当您创建函数时,类型还没有创建。不相关,但是:为什么您要使用类型开始。您可以简单地将函数定义为
返回表(satir varchar(4000))
@a_horse_with_no_name:函数签名中的类型修饰符被丢弃(请查看;没有可见的
typmod
字段)。如果要保留它们,您需要一个自定义类型(尽管域通常比单列组合简单)。是的,该类型是在与函数相同的架构中创建的。我将docker文件更改为在函数之前创建类型,如问题的编辑中所示。我仍然收到错误消息。