X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1AA7C9DCBE3; Sun, 11 Dec 2005 13:54:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06322-07; Sun, 11 Dec 2005 13:54:16 -0400 (AST) X-Greylist: delayed 00:10:03.650768 by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from rwcrmhc12.comcast.net (unknown [216.148.227.153]) by postgresql.org (Postfix) with ESMTP id C5F869DCAC0; Sun, 11 Dec 2005 13:54:14 -0400 (AST) Received: from cfgod (pcp08670491pcs.500ash01.tn.comcast.net[69.137.84.227]) by comcast.net (rwcrmhc13) with SMTP id <20051211174403015004ti7de>; Sun, 11 Dec 2005 17:44:09 +0000 From: "Foster, Stephen" To: "'Tom Lane'" Cc: "'Michael Fuhr'" , , Subject: Re: [SQL] Looking for information on PostgreSQL Stored Procedures Date: Sun, 11 Dec 2005 11:47:29 -0600 Message-ID: <000001c5fe7a$f95c2d00$2101a8c0@cfgod> MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1250" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2616 Importance: Normal In-Reply-To: <17301.1134320658@sss.pgh.pa.us> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.516 required=5 tests=[AWL=-0.803, DNS_FROM_RFC_POST=1.44, DNS_FROM_RFC_WHOIS=0.879] X-Spam-Score: 1.516 X-Spam-Level: * X-Archive-Number: 200512/537 X-Sequence-Number: 88100 Trying a totally different approach. Simple procedure that I'm using to use as learn opportunity in stored procedures in PostgreSQL prior to migrating a complex web site. Call it a training example if you will. Goal is to learn the correct process of working with cursors on complex queries in PostgreSQL before investing hours of work migrating a web site and moving some of the complex procedures to the database to simplify a process. Using this simple example, CREATE FUNCTION sp_removedups() RETURNS void AS $BODY$ DECLARE lastname varchar(255); fname varchar(255); id bigint; DECLARE NewListCursor CURSOR FOR SELECT Name, id FROM MailingList ORDER BY Name; BEGIN OPEN NewListCursor; LastName := ""; FETCH NEXT FROM NewListCursor INTO fname, id; 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; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; On the BEGIN/END; yes you are right it was missing. I'm converting a MS-2000 SQL example to PostgreSQL. Error according to pgadminIII is on line 11. Which should be the "LastName := "";" line. Before someone says it there is a better way of do this but it was a simple example before I dived in to the real ones. Second question/problem is how do you determine if the query has reached the end. Mentioned on the WHILE line. I have another project after this one I'm about to tackle that will be even more complex. So the sooner I can grasp the store procedures in this database the better off I will be. If there is a book somewhere that will clearly define the command set please let me know. This way determine what I can and can't do. The web language I use I can go back and fore with no problems but am think some of the processing that it is currently doing would be faster if I move it to the database side. Thanks for any help, Lee Foster -- 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