For Loop in PostGIS

From: Bryan Manuel <iceviper73(at)hotmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: For Loop in PostGIS
Date: 2007-12-05 04:48:00
Message-ID: BAY132-W26B6E64BF594FD48679E31DC6E0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


I am new to postgresql and I'm working with two tables, both having a geometry for postGIS. What I am trying to do is get the five nearest people from one list for every person in the second. I was trying to do this in a for loop - all I'm trying to do for now is display the 5 people for each person in the one list.

This code works as a command line argument to psql, and correctly finds five people for one query:

select lastname, city from eng_alumni order by ST_distance(point_geom, (select the_geom from points where text = 'Smith')) asc limit 5;

I tried to follow a for loop using the documentation, but it is not working. This seems like something that a for loop would work well for, at least in other languages that I have learned. Here is the code that I tried (running from a command line)

create table temp;
FOR temp IN SELECT text, the_geom FROM points ORDER BY text LOOP select lastname, latitude, longitude from eng_alumni order by ST_distance(point_geom, (select the_geom from temp)) asc limit 5;END LOOP;

Any help would be greatly appreciated.

Thanks,

Bryan Manuel

_________________________________________________________________
Use fowl language with Chicktionary. Click here to start playing!
http://puzzles.sympatico.msn.ca/chicktionary/index.html?icid=htmlsig

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Cedric BUSCHINI 2007-12-05 07:53:07 Vacuum Problem
Previous Message Richard Broersma Jr 2007-12-05 01:46:26 Re: error error