Received: from foghorn.airs.com (foghorn.airs.com [63.201.54.26]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f1O6Pnx73178 for ; Sat, 24 Feb 2001 01:25:50 -0500 (EST) (envelope-from ian@airs.com) Received: (qmail 19152 invoked by uid 10); 24 Feb 2001 06:25:47 -0000 Received: (qmail 7191 invoked by uid 269); 24 Feb 2001 06:25:43 -0000 To: Ken Kline Cc: pgsql-sql@postgresql.org Subject: Re: greetings References: <3A974086.EF665152@oldbs.com> From: Ian Lance Taylor Date: 23 Feb 2001 22:25:43 -0800 In-Reply-To: Ken Kline's message of "Sat, 24 Feb 2001 00:03:02 -0500" Message-ID: Lines: 49 User-Agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Archive-Number: 200102/380 X-Sequence-Number: 1585 Ken Kline writes: > I have just joined the list a few days ago and am trying quite hard > to come up to speed with pgsql but i find documentaion frustratiing. > I think maybe it;s just a matter of finding things that are of the > correct > scope. I've been an Oracle developer for over 6 years so often I > know what it is I want to do but something is just a little different. > If there are others on the list that learned in Oracle then pgsql > please tell me what you think are the best resources. > > Recently I did a google search on the key words "postgresql cursor loop" > > the example below is all I could come up with but it doesn't seem > to work is this for an older version or am I just overlooking > something simple? > > thanks > > Ken > > DECLARE emp_cursor CURSOR FOR > SELECT Salary, Title, Start, Stop > FROM Employee; > OPEN emp_cursor; > loop: > FETCH emp_cursor INTO :salary, :start, :stop; > if no-data returned then goto finished; > find position in linked list to insert this information; > goto loop; > finished: > CLOSE emp_cursor; PL/pgSQL does not support cursors. It also does not support goto. You can write the above as something like (untested): FOR emprec IN SELECT Salary, Title, Start, Stop FROM Employee LOOP IF no-data returned then EXIT; END LOOP; I have a patch adding cursors to PL/pgSQL. You can find it at http://www.airs.com/ian/pgsql-cursor.html This patch will not be in 7.1, but it may be in 7.2. However, it will not help you with the lack of goto. You shouldn't really use goto for a simple program like your example. But perhaps you are doing something more complex in your real code. Ian