Can anyone see what's wrong with the below simple function? Is it a simple syntax error or something else? I'm using postgreSQL 8.4. Thanks in advance
CREATE OR REPLACE FUNCTION get_source_from_closest_road_to_point(IN point geometry)
RETURNS integer AS
$BODY$
DECLARE --- Nothing to declare
query varchar;
rec RECORD;
BEGIN
query = 'SELECT p.source FROM project AS p
WHERE ST_CONTAINS(ST_BUFFER('|| $1 ||',0.001),p.the_geom)
AND p.clazz NOT IN (''11'',''12'') -- Motorway or motorway entrance exit ways
ORDER BY st_distance(st_closestpoint(p.the_geom::geometry, '|| $1 ||'::geometry), '|| $1 ||'::geometry) ASC LIMIT 1';
FOR rec IN EXECUTE query LOOP
RETURN rec.source;
END LOOP;
END; $BODY$
LANGUAGE 'plpgsql' VOLATILE
I'm using the command:
explain analyze select * from get_source_from_closest_road_to_point(ST_GeomFromText('Point(-6.3047272 53.4030415)', 4326));
But get the error:
ERROR: operator is not unique: unknown || geometry
LINE 2: ... WHERE ST_CONTAINS(ST_BUFFER('|| $1 ||...
^
HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
QUERY: SELECT 'SELECT p.source FROM project AS p
WHERE ST_CONTAINS(ST_BUFFER('|| $1 ||',0.001),p.the_geom)
AND p.clazz NOT IN (''11'',''12'') -- Motorway or motorway entrance exit ways
'|| $1 ||'::geometry), '|| $1 ||'::geometry) ASC LIMIT 1'
C ONTEXT: PL/pgSQL function "get_source_from_closest_road_to_point" line 6 at assignment
********** Error **********
ERROR: operator is not unique: unknown || geometry
SQL state: 42725