Received: from mail.perdue.net (c696732-a.west1.ia.home.com [24.22.227.157]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f2EEvex20745 for ; Wed, 14 Mar 2001 09:57:40 -0500 (EST) (envelope-from tperdue@mail.perdue.net) Received: (from tperdue@localhost) by mail.perdue.net (8.11.2/8.11.2/Debian 8.11.2-1) id f2EEuZR11860 for pgsql-sql@postgresql.org; Wed, 14 Mar 2001 08:56:35 -0600 Date: Wed, 14 Mar 2001 08:56:35 -0600 From: Tim Perdue To: pgsql-sql@postgresql.org Subject: PL/pgSQL "compilation error" Message-ID: <20010314085635.O670@mail.perdue.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.12i X-Archive-Number: 200103/273 X-Sequence-Number: 1932 Hello all - I apologize for the newbie-esque question, but the debug output from postgres when you have a bug in your PL/pgSQL procedure is none to detailed. I've created the following procedure and am getting an error when I try to update the table. The error is something like "parse error near ; on line 50". Line 50 is the last line. There's probably something glaring wrong in here that I'm not seeing, but any help would be appreciated. I don't know if the \ at the end of the line is a problem, but those were added late in the game and didn't change the error message ;-) Tim CREATE FUNCTION artifactgroup_update_agg () RETURNS OPAQUE AS ' BEGIN -- -- see if they are moving to a new artifacttype -- if so, its a more complex operation -- IF NEW.group_artifact_id <> OLD.group_artifact_id THEN -- -- transferred artifacts always have a status of 1 -- so we will increment the new artifacttypes sums -- UPDATE artifact_counts_agg SET count=count+1, open_count=open_count+1 \ WHERE group_artifact_id=NEW.group_artifact_id; -- -- now see how to increment/decrement the old types sums -- IF NEW.status_id <> OLD.status_id THEN IF OLD.status_id = 2 THEN UPDATE artifact_counts_agg SET count=count-1 \ WHERE group_artifact_id=OLD.group_artifact_id; -- -- no need to do anything if it was in deleted status -- END IF; ELSE -- -- Was already in open status before -- UPDATE artifact_counts_agg SET count=count-1, open_count=open_count-1 \ WHERE group_artifact_id=OLD.group_artifact_id; END IF; ELSE -- -- just need to evaluate the status flag and -- increment/decrement the counter as necessary -- IF NEW.status_id <> OLD.status_id THEN IF new.status_id = 1 THEN UPDATE artifact_counts_agg SET open_count=open_count+1 \ WHERE group_artifact_id=new.group_artifact_id; ELSE IF new.status_id = 2 THEN UPDATE artifact_counts_agg SET open_count=open_count-1 \ WHERE group_artifact_id=new.group_artifact_id; ELSE IF new.status_id = 3 THEN UPDATE artifact_counts_agg SET open_count=open_count-1,count=count-1 \ WHERE group_artifact_id=new.group_artifact_id; END IF; END IF; END IF; RETURN NEW; END; ' LANGUAGE 'plpgsql'; CREATE TRIGGER artifactgroup_update_trig AFTER UPDATE ON artifact FOR EACH ROW EXECUTE PROCEDURE artifactgroup_update_agg(); -- Founder - PHPBuilder.com / Geocrawler.com Lead Developer - SourceForge VA Linux Systems