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.
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.
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.
Related
I installed postgresql and postgresql-plpython-10 (using apt) on a new machine running Ubuntu server 18.04
and I have reinstated a Postgresql database (extracted using pg_dumpall) from another machine onto a new machine (Linux).
I checked that the trackspreadsheetnztplpy function exists in the database and the table nztgsheet exists. I reran the function on the old machine and it worked perfectly. I checked plpythonu is installed on the new machine using psql command: \dL.
SQL error:
ERROR: syntax error at or near "FUNCTION"
LINE 1: ...H ROW WHEN (OLD.* IS DISTINCT FROM NEW.*) EXECUTE FUNCTION t...
^
In statement:
CREATE TRIGGER trackspreadsheetnzt AFTER UPDATE ON nztgsheet FOR EACH ROW WHEN (OLD.* IS DISTINCT FROM NEW.*) EXECUTE FUNCTION trackspreadsheetnztplpy();
I expected the trigger function to work, but it throws a syntax error instead.
The EXECUTE FUNCTION syntax for CREATE TRIGGER statements was introduced in Postgres 11.
In Postgres 10, you need to say EXECUTE PROCEDURE instead.
This syntax was deprecated in Postgres 11 with the introduction of procedures, which are distinct from functions and cannot be used to implement a trigger.
If you are trying to add trigger function from pgadmin UI,
In the code tab you need to specify function from BEGIN to END, as postgres implicitly specifies in the code " CREATE OR REPLACE FUNCTION ****()
RETURNS TRIGGER
AS
$$"
I'm constantly getting this error in DataGrip when trying to create a procedure in PostgreSQL
[42601] ERROR: syntax error at or near "PROCEDURE"
This is the block I'm trying to run (It works on my friend's mac)
CREATE PROCEDURE name_p(IN modelNumber integer)
LANGUAGE plpgsql
AS $$
BEGIN
DELETE FROM product WHERE model = modelNumber;
DELETE FROM pc WHERE model = modelNumber;
END;
$$;
I got Postgres 11.2 installed, so everything should be up to date..
Found a solution!
Apparently you need to change the port in the config file for PostgreSQL. It's all described in this thread.
I've got an existing Postgres 9.6 database on Google Cloud that has the PostGIS extension enabled, however whenever I try to create a table with a column with the geography type or select the PostGIS version I get an error.
For creating the geography column the error is non-descriptive — just an arrow pointing to the word geography in the following statement
create table place(coordinate geography(POINT,4326));
The version error looks as follows:
select postgis_full_version();
ERROR: could not access file "$libdir/postgis-2.3": No such file or directory
CONTEXT: SQL statement "SELECT postgis_lib_version()"
PL/pgSQL function postgis_full_version() line 22 at SQL statement
The create extension statement confirms it is already installed though e.g
create extension postgis;
error: the extension already exists
I've tried running these commands as the postgres user and as another user who's been granted permissions on the database in question but neither seem to work. Any help would be appreciated.
It's simpler than you think:
Your hosting privider has goofed up the PostGIS installation.
It looks like the file is really missing, or something else on the operating system level is misconfigured.
You should gripe at Google.
I use primary pgAdmin to browse and edit my PostgreSQL database. Now I would like to use PhpStorm.
In PhpStorm I can browse my tables, but I can not edit data. When I try I get error:
[42704] ERROR: type "hstore" does not exist
Kde: compilation of PL/pgSQL function "on_update" near line 3
Function on_update is on update trigger and it save old row to history table and it uses hstore type.
PhpStorm uses postgresql-9.4-1201.jdbc4.jar driver. I don't know if it is driver error or PhpStorm error. I know that in pgAdmin it works and in PhpStorm not.
I work with same environment as Vojtěch and I have found that the extension is indeed created and present. But in different schema (public) then the current connection operates (the PostgreSQL search_path). There is probably bug in PhpStorm as its not respecting PostgreSQL user's default search_path.
Some workarounds (for DB console only):
In database console you use RESET SEARCH_PATH; statement.
You can enforce search_path on JDBC connection, see the question.
I am trying to solve a problem related to what appears to be duplicated functions in a postgis database (original question here), but in my testing I'm getting something very odd happening. I have installed a new postgres database in openshift, activated the postgis extensions, and tried doing a transform twice. The first time it worked, the second time it didn't. Here is the full command line:
test=# CREATE EXTENSION postgis;
CREATE EXTENSION
test=# CREATE EXTENSION postgis_topology;
CREATE EXTENSION
test=# SELECT ST_Transform('SRID=3857;POINT(-10000000 5200000)'::geometry,4326);
st_transform
----------------------------------------------------
0101000020E6100000E0C1F1C2377556C0F04DCF5946214540
(1 row)
test=# SELECT ST_Transform('SRID=3857;POINT(-10000000 5200000)'::geometry,4326);
ERROR: transform: couldn't project point (-1e+07 5.2e+06 0): failed to load NAD27-83 correction file (-38)
test=#
I executed these commands straight after each other. I also tried creating a new database a couple of times but got the same behaviour in each. Why would it work once but not the second time?
You need to install package called 'proj-nad'
So 'yum install proj-nad'
Thats is.