pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Foster, Stephen <stephenlfoster@comcast.net>
To: 'Michael Fuhr' <mike@fuhr.org>
To: 'Douglas McNaught' <doug@mcnaught.org>
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 12:07:26 -0600
Message-ID: <000001c5fe7d$be7f5470$2101a8c0@cfgod> (raw)
In-Reply-To: <20051211172218.GA87286@winnie.fuhr.org>

Thanks Michael!  Guess I should have drunk more coffee before replying.
I must have miss that.

-----Original Message-----
From: Michael Fuhr [mailto:mike@fuhr.org] 
Sent: Sunday, December 11, 2005 11:22 AM
To: Douglas McNaught
Cc: Foster, Stephen; pgsql-general@postgresql.org;
pgsql-sql@postgresql.org
Subject: Re: [SQL] [GENERAL] Looking for information on PostgreSQL
Stored Procedures

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

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/197 - Release Date:
12/9/2005
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/197 - Release Date:
12/9/2005
 




view thread (10+ messages)  latest in thread

Message-ID: <000001c5fe7d$be7f5470$2101a8c0@cfgod>
Permalink:  ../000001c5fe7d$be7f5470$2101a8c0@cfgod/
Also on:    postgresql.org/message-id/000001c5fe7d$be7f5470$2101a8c0@cfgod

 · 

reply

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: stephenlfoster@comcast.net, mike@fuhr.org, doug@mcnaught.org, pgsql-general@postgresql.org
  Subject: Re: [SQL] Looking for information on PostgreSQL Stored Procedures
  In-Reply-To: <000001c5fe7d$be7f5470$2101a8c0@cfgod>

* 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