PL/pgSQL "compilation error"

From: Tim Perdue <tim(at)perdue(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: PL/pgSQL "compilation error"
Date: 2001-03-14 14:56:35
Message-ID: 20010314085635.O670@mail.perdue.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-sql

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

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2001-03-14 15:33:49 Re: PL/pgSQL "compilation error"
Previous Message Pablo Gosse 2001-03-13 21:07:49 missing page

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2001-03-14 15:33:49 Re: PL/pgSQL "compilation error"
Previous Message Alexaki Sofia 2001-03-14 14:51:45