如何为 Postgresql 安装地球距离(和需求立方体)模块?

Eva*_*oll 4 postgresql ubuntu-10.10

我需要安装earthdistance,一个 Postgresql 的扩展。它的页面说:

Earthdistance 模块提供了两种不同的方法来计算地球表面的大圆距离。首先描述的依赖于cube包(必须在安装earthdistance之前安装)。第二个基于内置点数据类型,使用经度和纬度作为坐标。

这似乎是真的。。

dealermade=# CREATE EXTENSION earthdistance FROM unpackaged;
ERROR:  required extension "cube" is not installed
Run Code Online (Sandbox Code Playgroud)

但是,我不能安装cube任何

dealermade=# CREATE EXTENSION cube FROM unpackaged;
ERROR:  type "cube" does not exist
Run Code Online (Sandbox Code Playgroud)

cube扩展需要cube它提供的类型似乎很尴尬。我正在使用PostgreSQL 9.1.1. 我在 Ubuntu 上执行此操作,并且postgresql-contrib-9.1安装了配套软件包。也就是说,cube.sql我的系统上没有。

如果我尝试earthdistance.sql直接安装,我会得到这个

$ psql -d db -f /usr/share/postgresql/9.1/extension/earthdistance--1.0.sql
CREATE FUNCTION
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:31: ERROR:  type "cube" does not exist
CREATE FUNCTION
CREATE FUNCTION
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:49: ERROR:  type "earth" does not exist
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:55: ERROR:  type earth does not exist
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:61: ERROR:  type earth does not exist
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:67: ERROR:  type earth does not exist
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:73: ERROR:  type earth does not exist
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:79: ERROR:  could not access file "MODULE_PATHNAME": No such file or directory
psql:/usr/share/postgresql/9.1/extension/earthdistance--1.0.sql:88: ERROR:  function geo_distance(point, point) does not exist
Run Code Online (Sandbox Code Playgroud)

小智 11

FROM unpackaged 仅适用于已经作为 contrib 模块安装(即从 9.0 升级)并且您需要将其转换为扩展的情况。因此,只需:

CREATE EXTENSION cube;
CREATE EXTENSION earthdistance;
Run Code Online (Sandbox Code Playgroud)