我的数据库中有一个 UDF,它基本上试图根据一些输入数据(地理/名称/类型)获取一个车站(例如公共汽车/火车)。在此函数中,我尝试检查是否有任何与给定值匹配的行:
SELECT
COUNT(s.id)
INTO
firsttry
FROM
geographic.stations AS s
WHERE
ST_DWithin(s.the_geom,plocation,0.0017)
AND
s.name <-> pname < 0.8
AND
s.type ~ stype;
firsttry变量现在包含值 1。如果我使用以下(稍微扩展的)SELECT 语句,我不会得到任何结果:
RETURN query SELECT
s.id, s.name, s.type, s.the_geom,
similarity(
regexp_replace(s.name::text,'(Hauptbahnhof|Hbf)','Hbf'),
regexp_replace(pname::text,'(Hauptbahnhof|Hbf)','Hbf')
)::double precision AS sml,
st_distance(s.the_geom,plocation) As dist from geographic.stations AS s
WHERE ST_DWithin(s.the_geom,plocation,0.0017) and s.name <-> pname < 0.8
AND s.type ~ stype
ORDER BY dist asc,sml desc LIMIT 1;
参数如下:
stype = '^railway'
pname = 'Amsterdam Science Park'
plocation = ST_GeomFromEWKT('SRID=4326;POINT(4.9492530 52.3531670)')
我需要返回的元组是:
id name type geom (displayed as ST_AsText)
909658;"Amsterdam Sciencepark";"railway_station";"POINT(4.9482893 52.352904)"
对于许多其他站点,相同的 UDF 的返回效果非常好,但这是一个(或多个)无法正常工作的站点。有什么建议么?
PS <->运算符的使用来自pg_trgm模块。