From: Michael Fuhr <mike@fuhr.org>
To: Douglas McNaught <doug@mcnaught.org>
Cc: Foster, Stephen <stephenlfoster@comcast.net>
Cc: pgsql-general@postgresql.org
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Looking for information on PostgreSQL Stored Procedures
Date: Sun, 11 Dec 2005 10:22:18 -0700
Message-ID: <20051211172218.GA87286@winnie.fuhr.org> (raw)
In-Reply-To: <m2bqznh9m0.fsf@Douglas-McNaughts-Powerbook.local>
References: <000001c5fe70$f5e51330$2101a8c0@cfgod>
<m2bqznh9m0.fsf@Douglas-McNaughts-Powerbook.local>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mike@fuhr.org, doug@mcnaught.org, stephenlfoster@comcast.net, pgsql-general@postgresql.org
Subject: Re: [SQL] Looking for information on PostgreSQL Stored Procedures
In-Reply-To: <20051211172218.GA87286@winnie.fuhr.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox