On Sun, Dec 11, 2005 at 11:38:47AM -0500, Douglas McNaught wrote: > "Foster, Stephen" <stephenlfoster@xxxxxxxxxxx> writes: > > > WHILE (--Lost on variable name for end of query; EmptyQueryResponse <> > > 0? --) > > BEGIN > > IF LastName = fname THEN > > DELETE FROM MailingList WHERE id = id; > > END IF; > > LastName := fname; > > FETCH NEXT FROM NewListCursor INTO fname, id; > > END; > > CLOSE NewListCursor; > > $BODY$ > > LANGUAGE 'sql' VOLATILE; > > You can't do any looping or other control structures in an SQL > function. Use PL/pgSQL instead. And as I mentioned in my previous post, you can loop through query results without messing around with an explicit cursor. CREATE FUNCTION testfunc() RETURNS void AS $$ DECLARE row record; BEGIN FOR row IN SELECT * FROM tablename ORDER BY whatever LOOP -- do stuff that refers to row.column_name END LOOP; RETURN; END; $$ LANGUAGE plpgsql; -- Michael Fuhr