postgresql - postgres - 错误 : operator does not exist

标签 postgresql postgis

同样,我有一个在本地运行良好的函数,但将其移动到网上会产生一个大错误...从有人指出我传递的参数数量不准确的响应中得到提示,在这种情况下,我仔细检查以确保我将 5 个参数传递给函数本身......

Query failed: ERROR: operator does not exist: point <@> point HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.

查询是这样的:

BEGIN; SELECT zip_proximity_sum('zc',                                                                                                                                                                  
    (SELECT g.lat FROM geocoded g                                                                                                                                                                              
    LEFT JOIN masterfile m ON g.recordid = m.id                                                                                                                                                                
    WHERE m.zip = '10050' ORDER BY m.id LIMIT 1),                                                                                                                                                             
    (SELECT g.lon FROM geocoded g                                                                                                                                                                              
    LEFT JOIN masterfile m ON g.recordid = m.id                                                                                                                                                                
    WHERE m.zip = '10050' ORDER BY m.id LIMIT 1),                                                                                                                                                             
    (SELECT m.zip FROM geocoded g                                                                                                                                                                              
    LEFT JOIN masterfile m ON g.recordid = m.id                                                                                                                                                                
    WHERE m.zip = '10050' ORDER BY m.id LIMIT 1)                                                                                                                                                              
    ,10);

PG函数是这样的:

CREATE OR REPLACE FUNCTION zip_proximity_sum(refcursor, numeric, numeric, character, numeric)
  RETURNS refcursor AS
$BODY$ 
    BEGIN 

        OPEN $1 FOR 
            SELECT r.zip, point($2,$3) <@> point(g.lat, g.lon) AS distance
            FROM
            geocoded g LEFT JOIN masterfile r ON g.recordid = r.id 
            WHERE (geo_distance( point($2,$3),point(g.lat,g.lon)) < $5)
            ORDER BY r.zip, distance;
        RETURN $1; 
    END; 
    $BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100;

最佳答案

具体命令如下:

create extension cube;
create extension earthdistance;
select (point(-0.1277,51.5073) <@> point(-74.006,40.7144)) as distance;

     distance     
------------------
 3461.10547602474
(1 row)

请注意, 是使用LONGITUDE FIRST 创建的。根据 documentation :

Points are taken as (longitude, latitude) and not vice versa because longitude is closer to the intuitive idea of x-axis and latitude to y-axis.

这是糟糕的设计……但事实就是如此。

关于postgresql - postgres - 错误 : operator does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2665786/

相关文章:

postgresql - 如何从 Postgresql 数据库获取数据到 Angular 网站?

java - hibernate 启动很慢

python - 是否可以在 Django 中查询查询对象?

python - Django cache.set() 导致重复键错误

ubuntu-12.04 - Ubuntu 12.04、PostgreSQL-9.1 - 无法访问 $libdir/postgis-2.0

php - PostgreSQL 数据库似乎不适用于 GeoServer

sql - 如何绑定(bind)数组参数以在 Postgres 中使用 IN 运算符进行过滤

algorithm - ST_Within/ST_Contains 如何处理地理数据?

python - 初始化几何类型的空列的合适值是多少

hibernate-spatial:用于检索几何的 sql 查询