1

我已经安装了 PostGis 的 PostgreSQL,我尝试运行以下命令:

SELECT N1.edname AS "Borders Royal Exchange A"
FROM eds_census2011 N1, eds_census2011 N2
WHERE Touch(N1.the_geom, N2.the_geom)
AND N2 = 'Royal Exchange A'

我收到一个错误(如下)我必须添加到 Postgres 或启用某些东西吗?

ERROR:  function touch(geometry, geometry) does not exist
LINE 3: WHERE Touch(N1.the_geom, N2.the_geom)
              ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

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

ERROR: function touch(geometry, geometry) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Character: 96
4

2 回答 2

2

运行这两个查询(在您尝试上述查询的同一会话中)来确定问题:

该函数touch()存在于哪个模式中?

SELECT p.proname, n.nspname
FROM   pg_proc p
JOIN   pg_namespace n ON n.oid = p.pronamespace
WHERE  proname = 'touch';

search_path我的角色的当前架构是什么:

SHOW search_path;

如果函数存在,模式必须在当前search_path,以便 Postgres 可以找到它。如何适应search_path
search_path 如何影响标识符解析和“当前模式”

顺便说一句,我在 Postgis 手册的函数参考中找不到函数Touch()。有一个叫做ST_Touches()。有机会你是说那个吗?

请注意,此查询的成本为 O(N²),因为它为eds_census2011. 如果您的病情N2.edname = 'Royal Exchange A'有足够的选择性,这将不是问题。

此外,您可能希望排除与附加WHERE项目连接的行,例如:

AND N1.pk_id <> N2.pk_id 

更新后出错

您更新的查询更有意义:

SELECT N1.edname AS "Borders Royal Exchange A"
FROM   eds_census2011 N1, eds_census2011 N2
WHERE  ST_Touches(N1.the_geom, N2.the_geom)=1
AND    N2.edname = 'Royal Exchange A';

但是ST_Touches()返回boolean,所以 Where 子句应该是:

WHERE  ST_Touches(N1.the_geom, N2.the_geom)
于 2013-05-09T21:03:26.290 回答
0

明白了 - 感谢大家,使用了以下内容:

SELECT N1.edname AS "Borders Royal Exchange A"
FROM eds_census2011 N1, eds_census2011 N2
WHERE ST_Touches(N1.the_geom, N2.the_geom)
AND N2.edname = 'Royal Exchange A'
于 2013-05-09T21:40:27.313 回答