Postgresql 错误类型“”不存在
Postgresql Error type " " does not exist
我收到此错误:
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
编辑:
我更改了 docker 文件以在函数之前创建类型:
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/
我该如何解决?
您确定类型是在函数之前创建的吗?
类型是在与函数相同的架构中创建的吗? (是不是SET search_path在sql文件的某处使用了?)
$$ 和 $BODY$ 开始于 "dolar quoted string",它们以相同的($$ 或 $BODY$ 结束)。除了 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
成功了!
我收到此错误:
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
编辑: 我更改了 docker 文件以在函数之前创建类型:
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/
我该如何解决?
您确定类型是在函数之前创建的吗?
类型是在与函数相同的架构中创建的吗? (是不是SET search_path在sql文件的某处使用了?)
$$ 和 $BODY$ 开始于 "dolar quoted string",它们以相同的($$ 或 $BODY$ 结束)。除了 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
成功了!