3

I started recently using pgAdmin 4 after having used pgAdmin 3 for a long time.

The problem I have now is that I cannot replace existing functions that reference geometry objects. I am on Windows 10, and the current version of pgAdmin 4 is 2.1.

The PL/pgSQL function already exists in the database and it was created with flyway, psql or pgAdmin 3, and it works. The PostGIS extension is enabled.

Now I go in pgAdmin 4 and use the same login as ever, choose "Scripts"->"Create script" for the function, and then click F5 - "run Script" to create it.

What I get is an error:

ERROR:  type "geometry" does not exist
LINE 22:   v_location   geometry;

The same operation in pgAdmin 3 gives no error. The function has the search_path set correctly and can be created in pgAdmin3 and psql.

Actually I can create a dummy function in the query tool in pgadmin4 and compile it. See below:

set search_path=res_cc_01,public;
create or replace function test() returns text
  LANGUAGE plpgsql VOLATILE SECURITY DEFINER
  COST 100
  set search_path=res_cc_01,public
AS
$BODY$
DECLARE
    v_g geometry := ST_GeometryFromText('POINT(142.279859 -9.561480)',4326);
begin
    return 'xxx'::text;
end;
$BODY$

Only when recompiling through Scripts->Create Script then F5 ( Execute ) I got the error. What is the problem here?

I could not find a similar problem on the net, nor into the manuals. But I haven't read them all.

0

2 Answers 2

2

You're certainly missing the postgis extension in the current database. If you already have it installed in your server, just execute the following command to create the extension and so the missing data type:

CREATE EXTENSION postgis;

If it happens to be that you don't have it installed in your database server, you can find the installation instructions to many operating systems here.

6
  • Thank your for the fast answer, but this does not solve the problem. The postgis extension and others are already installed, the code is already running on the database, I only tried to make a small fix and compile it with PGAdmin4 using the Scripts->create scritps how I often did it in pgadmin 3. Compiling he changes with PGAdmin 3 is working. So it seems to me that this is a pgadmin 4 problem and not a server problem. Actually we use set search_path = mypath,public in the plpgsql code definition of the function, probably this is not working in pgadmin 4.
    – rimetnac
    Mar 28, 2018 at 11:11
  • That's really intriguing.. what happens if you paste the code of your function in a query tool window and try to execute it? I assume you have a CREATE OR REPLACE FUNCTION statement. I also use pgAdmin 4 (not a big fan though) with postgis and it works fine for me.
    – Jim Jones
    Mar 28, 2018 at 11:18
  • I added the query tool test function in the main thread. It is working there but not with Create Scripts.
    – rimetnac
    Mar 28, 2018 at 11:41
  • Now I see what you mean: I also got the same error : ERROR: FEHLER: Typ »geometry« existiert nicht LINE 16: v_g geometry := ST_GeometryFromText('POINT(142.279859 -9... I will upvote your question to see if somebody else knows the answer for what seems to be a bug to me. I will let you know if I find something.
    – Jim Jones
    Mar 28, 2018 at 11:59
  • Servus! I just see that pgAdmin4 is not coping well with this parameter SET search_path='res_cc_01, public' in your function. Leaving it out you can compile the function.. which is not a solution at all, but at least we know where the problem is.
    – Jim Jones
    Mar 28, 2018 at 12:07
2

The problem is caused by the way pgadmin 4 shows the plpgsql code when using Scripts-> Create Script. It adds unneeded quotes to the paths in the search_path directive that makes the entire search_path invalid. With an invalid search_path the compiler will not find the available extensions. We actually have an item with PGAdmin4 with Scripts->Create Script malfunction. In PgAdmin 3 the search_path directive used in the function was showed as alter function statement but in a correct form. Many thanks to Jim Jones for the precious analysis on this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.