Search Postgresql Archives

Re: [SQL] Looking for information on PostgreSQL Stored Procedures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux