Share Pastebin
Guest
Public paste!

Yancho

By: a guest | Jan 26th, 2008 | Syntax: SQL | Size: 0.69 KB | Hits: 121 | Expires: Never
Copy text to clipboard
  1. -- Function: give_source(text, integer, integer)
  2.  
  3. -- DROP FUNCTION give_source(text, integer, integer);
  4.  
  5. CREATE OR REPLACE FUNCTION give_source(text, integer, integer)
  6.   RETURNS integer AS
  7. $BODY$
  8.  
  9. DECLARE
  10.         pojnt ALIAS FOR $1;
  11.         box ALIAS FOR $2;
  12.         dist ALIAS FOR $3;
  13.  
  14.         r_source INTEGER;
  15.  
  16. BEGIN
  17.         SELECT source INTO r_source
  18.         FROM streets s
  19.         WHERE
  20.                 (
  21.                 the_geom && expand (pointfromtext(pojnt),box) AND
  22.                 distance (s.the_geom , pointfromtext(pojnt)) < dist
  23.                 )
  24.         ORDER BY distance (s.the_geom , pointfromtext(pojnt)) ASC
  25.         LIMIT 1;
  26.  
  27.         RETURN r_source;
  28. END;
  29. $BODY$
  30.   LANGUAGE 'plpgsql' VOLATILE;
  31. ALTER FUNCTION give_source(text, integer, integer) OWNER TO yancho;