Postgresql 错误:将sql文件插入postgis数据库时,函数addgeometrycolumn(未知..)出错
我正在尝试将空间文件导入到我的数据库中 首先,我使用Postgresql 错误:将sql文件插入postgis数据库时,函数addgeometrycolumn(未知..)出错,postgresql,maps,postgis,shapefile,geodjango,Postgresql,Maps,Postgis,Shapefile,Geodjango,我正在尝试将空间文件导入到我的数据库中 首先,我使用postgis模板创建了一个数据库,如下所示 createdb -T template_postgis database_name; 我的机器上已经安装了postgis POSTGIS="2.1.1 r12113" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.7.8" LIBJ
postgis模板创建了一个数据库,如下所示
createdb -T template_postgis database_name;
我的机器上已经安装了postgis
POSTGIS="2.1.1 r12113" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.7.8" LIBJSON="UNKNOWN" TOPOLOGY RASTER
Postgres版本:psql(9.3.2,服务器9.1.11)
其次,我将空间文件转换为sql文件,如下所示
shp2pgsql -s 3425 Aspire.shp test_for_shape_data database_name > shapefile_data.sql
现在我正试图将这个sql文件(shapefile\u data.sql)导入我的数据库(database\u name),如下所示
psql -d database_name username -f shapefile_data.sql
但是我得到了以下错误
user@user:~/user/spice$ psql -d psql -d database_name username -f shapefile_data.sql
SET
SET
BEGIN
psql:shapefile_data.sql:30: NOTICE: CREATE TABLE will create implicit sequence "test_for_shape_data_gid_seq" for serial column "test_for_shape_data.gid"
CREATE TABLE
psql:shapefile_data.sql:31: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "test_for_shape_data_pkey" for table "test_for_shape_data"
ALTER TABLE
psql:shapefile_data.sql:32: ERROR: function addgeometrycolumn(unknown, unknown, unknown, unknown, unknown, integer) is not unique
LINE 1: SELECT AddGeometryColumn('','test_for_shape_data','geom','42...
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
psql:shapefile_data.sql:33: ERROR: current transaction is aborted, commands ignored until end of transaction block
psql:shapefile_data.sql:34: ERROR: current transaction is aborted, commands ignored until end of transaction block
...........
.......
为什么它告诉我,即使我使用postgis模板创建了数据库,我也没有AddGeometryColumn
功能
那么如何避免这种情况呢
另外,当我试图手动启用postgis功能时,它会告诉我已经存在了
database_name=# CREATE EXTENSION postgis;
ERROR: type "spheroid" already exists
database_name=# CREATE EXTENSION postgis_topology;
ERROR: required extension "postgis" is not installed
那么,如何清除此错误并将shapefile sql文件插入到数据库中呢 听起来您已经安装了一个旧的PostGIS,它是由一个SQL脚本(扩展前支持)创建的。它可能只有一些您期望的功能和特性。当您安装了PostGIS 1.5模式和PostGIS 2.0等时,可能会发生这种行为
尝试从template0
创建数据库,然后运行createextensionpostgis代码>然后执行恢复。我怀疑您的模板\u postgis
包含旧版本的扩展模式
看