无法将带EPSG -1的几何列添加到postgres表

时间:2018-02-20 04:25:02

标签: sql postgresql postgis

我有一个带postgis 2.3的postgres 9.x数据库,我创建了一个名为scuma的新模式,我跟着这个tutorial

为了使postgis函数可用于新模式但是当我尝试执行

SELECT AddGeometryColumn('scuma','table1','attr6',-1,'POINT',2);

我收到此错误

ERROR:  type "public.geometry" does not exist
LINE 1: SELECT public.ST_SRID('POINT EMPTY'::public.geometry)
                                         ^
QUERY:  SELECT public.ST_SRID('POINT EMPTY'::public.geometry)
CONTEXT:  PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,character varying,integer,character varying,integer,boolean) line 56 at assignment
SQL statement "SELECT AddGeometryColumn('',$1,$2,$3,$4,$5,$6,$7)"
PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,integer,character varying,integer,boolean) line 5 at SQL statement

********** Error **********

ERROR: type "public.geometry" does not exist
SQL state: 42704
Context: PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,character varying,integer,character varying,integer,boolean) line 56 at assignment
SQL statement "SELECT AddGeometryColumn('',$1,$2,$3,$4,$5,$6,$7)"
PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,integer,character varying,integer,boolean) line 5 at SQL statement

我看到所有postgis函数都添加到我的新模式中,并且我已经将模式名称作为参数传递给函数,因此我不知道它为什么要查找public。这是postgis中的错误吗? 如果我运行此查询,它可以工作:

SELECT AddGeometryColumn('scuma','table1','attr6',4328,'POINT',2);

更新:这是\dx

的输出
gogu=# \dx
                                                                   List of installed extensions
         Name             | Version |   Schema   |                                                     Description                                                     
------------------------------+---------+------------+---------------------------------------------------------------------------------------------------------------------
address_standardizer         | 2.3.3   | public     | Used to parse an address into constituent elements. Generally used to support geocoding address normalization step.
address_standardizer_data_us | 2.3.3   | public     | Address Standardizer US dataset example
fuzzystrmatch                | 1.1     | public     | determine similarities and distance between strings
plpgsql                      | 1.0     | pg_catalog | PL/pgSQL procedural language
postgis                      | 2.3.3   | scuma      | PostGIS geometry, geography, and raster spatial types and functions
postgis_tiger_geocoder       | 2.3.3   | tiger      | PostGIS tiger geocoder and reverse geocoder
postgis_topology             | 2.3.3   | topology   | PostGIS topology spatial types and functions
(7 rows)

gogu=#

2 个答案:

答案 0 :(得分:1)

在该教程之后,您将所有postgis内容移动到“scuma”架构。

因此st_srid现在在scuma模式中定义,而不是在公共模式中定义。

所以你必须使用scuma.st_srid而不是public.st_srid。

请注意,您无需从“public”移动postgis函数,以便在其他模式中使用它们。

答案 1 :(得分:1)

我相信您只是想在错误的架构中获取postgis功能。如果未在public架构中使用扩展程序,则可以将其移至scuma,如此

ALTER EXTENSION postgis SET SCHEMA scuma;

或者您可以将其保留在公共模式中,但您需要指定扩展名的位置,如上面@ fradal83所述。