pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tim Perdue <tim@perdue.net>
To: pgsql-sql@postgresql.org
Subject: PL/pgSQL "compilation error"
Date: Wed, 14 Mar 2001 08:56:35 -0600
Message-ID: <20010314085635.O670@mail.perdue.net> (raw)

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



view thread (13+ messages)  latest in thread

Message-ID: <20010314085635.O670@mail.perdue.net>
Permalink:  ../20010314085635.O670@mail.perdue.net/
Also on:    postgresql.org/message-id/20010314085635.O670@mail.perdue.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tim@perdue.net, pgsql-sql@postgresql.org
  Subject: Re: PL/pgSQL "compilation error"
  In-Reply-To: <20010314085635.O670@mail.perdue.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox