Received: from c014.sfo.cp.net (c014-h001.c014.sfo.cp.net [209.228.12.65]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f1OJAsx95154 for ; Sat, 24 Feb 2001 14:10:54 -0500 (EST) (envelope-from ken@oldbs.com) Received: (cpmta 19453 invoked from network); 24 Feb 2001 11:10:51 -0800 Received: from unknown (HELO oldbs.com) (216.91.245.19) by smtp.oldbs.com (209.228.12.65) with SMTP; 24 Feb 2001 11:10:51 -0800 X-Sent: 24 Feb 2001 19:10:51 GMT Message-ID: <3A980760.87DAC5AC@oldbs.com> Date: Sat, 24 Feb 2001 14:11:28 -0500 From: Ken Kline X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.16-22min_for_stan i586) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane CC: Ian Lance Taylor , pgsql-sql@postgresql.org Subject: Re: greetings References: <3A974086.EF665152@oldbs.com> <11378.982997569@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200102/386 X-Sequence-Number: 1591 it is to be server side code.... the code I gave you was merely an example of a cursor that I found when I did a search... http://www.armed.net/how/pg001676.htm orginally what I wanted to do was this: INSERT INTO pledge_classes (semester, year) SELECT distinct pseason, pyear from load_bros WHERE pyear is not null AND pseason is not null order by pyear, pseason; however pgsql does not allow order by in an INSERT-SELECT statement so i thought maybe I could do something like this: DECLARE CURSOR get_rows AS SELECT DISTINCT pseason, pyear FROM load_members WHERE pyear IS NOT NULL AND pseason IS NOT NULL ORDER BY pyear, pseason; BEGIN FOR rec IN get rows LOOP INSERT INTO pledge_classes (semester, year) VALUES (rec.pseason, rec.pyear); END LOOP; COMMIT; END; / Well, all the code I just showed you works in orcacle but pgsql is a little different and even though the book has an example of a cursor http://www.postgresql.org/docs/aw_pgsql_book/node142.html it does not explain before hand 1) the format of an anoymous block 2) how to loop a cursor 3) how to reference columns froma cursor row (ie rec.column_name) thanks Ken Tom Lane wrote: > Ian Lance Taylor writes: > > PL/pgSQL does not support cursors. It also does not support goto. > > The context is pretty unclear here, but perhaps he needs ecpg not > plpgsql ... is this to be client- or server-side code? > > regards, tom lane