Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: type "..." does not exist in Postgresql

I get this error:

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

I am restoring my database in a docker container like this:

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/

Here's type definition in schema.sql file:

CREATE TYPE tool_parse_numbers_record AS (
  satir character varying(4000)
);

Here's top part of function definition in 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

And this is how database is restored:

CREATE FUNCTION tool_parse_numbers(pstr text, pdelimeter text DEFAULT 
'|'::text) RETURNS SETOF tool_parse_numbers_record
LANGUAGE plpgsql SECURITY DEFINER
AS $BODY$
DECLARE

EDIT: I changed dockerfile to create types before functions:

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/

How do I fix it?

like image 697
Uluz Avatar asked Oct 14 '25 05:10

Uluz


1 Answers

Are you sure that the type is created before the function?

Is the type created in the same schema as the function? (Is not SET search_path somewhere in the sql file used?)

$$ and $BODY$ starts "dolar quoted string", which are terminated by the same ($$ or $BODY$). Instead of BODY you can have any characters (or any), it just allowes to write $$, ", etc. inside the string without problems. Why postgres use $BODY$ and not $ILOVEBEER$ remains unknown.

like image 109
Petr Avatar answered Oct 17 '25 23:10

Petr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!