Re: [SQL] Looking for information on PostgreSQL Stored Procedures
От | Michael Fuhr |
---|---|
Тема | Re: [SQL] Looking for information on PostgreSQL Stored Procedures |
Дата | |
Msg-id | 20051211172218.GA87286@winnie.fuhr.org обсуждение исходный текст |
Ответ на | Re: [SQL] Looking for information on PostgreSQL Stored Procedures (Douglas McNaught <doug@mcnaught.org>) |
Ответы |
Re: [SQL] Looking for information on PostgreSQL Stored Procedures
|
Список | pgsql-general |
On Sun, Dec 11, 2005 at 11:38:47AM -0500, Douglas McNaught wrote: > "Foster, Stephen" <stephenlfoster@comcast.net> 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
В списке pgsql-general по дате отправления: