X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 66ED2D1EA84 for ; Mon, 29 Mar 2004 17:12:47 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 85558-02 for ; Mon, 29 Mar 2004 13:12:42 -0400 (AST) Received: from bonobo.illumining.com (unknown [81.187.189.7]) by svr1.postgresql.org (Postfix) with ESMTP id C34CCD1D2A0 for ; Mon, 29 Mar 2004 13:12:38 -0400 (AST) Received: from Jon ([192.168.1.103]) by bonobo.illumining.com (8.12.8/8.12.8) with SMTP id i2THJSTX013368; Mon, 29 Mar 2004 18:19:29 +0100 From: "Jon Poulton" To: Cc: Subject: Question on pgsql trigger Date: Mon, 29 Mar 2004 18:12:46 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/22 X-Sequence-Number: 17397 Hi there, Im having a go at writing my first set of triggers for postgres and Im having trouble with an error message which the trigger produces when it tries to compile/call the function Ive written in pgsql. The error message is: ERROR: syntax error at or near ";" CONTEXT: compile of PL/pgSQL function "text_update" near line 31 I cant find the error! As far as I can see the syntax is fine from whats in the manual. Can anyone see what the problem with the function below is: CREATE FUNCTION text_update() RETURNS TRIGGER AS' DECLARE allText TEXT; currentRecord RECORD; BEGIN IF TG_WHEN = BEFORE THEN RAISE EXCEPTION ''Trigger function text_update should not be called before INSERT/UPDATE/DELETE''; END IF; IF TG_LEVEL = STATEMENT THEN RAISE EXCEPTION ''Trigger function text_update should be called as a row level trigger''; END IF; IF TG_OP = DELETE THEN DELETE FROM cks_messagetext WHERE cks_messagetext.id = OLD.id; RETURN OLD; ELSIF TG_OP = UPDATE THEN FOR currentRecord IN SELECT textdata FROM cks_part WHERE cks_part.type = 1 AND cks_part.sourcemessageid = NEW.id LOOP allText := allText || '' '' || currentRecord.textdata; END LOOP; allText := allText || '' '' || NEW.subject; UPDATE cks_messagetext SET cks_messagetext.textdata = allText WHERE cks_messagetext.id = NEW.id; RETURN NEW; ELSIF TG_OP = INSERT THEN FOR currentRecord IN SELECT textdata FROM cks_part WHERE cks_part.type = 1 AND cks_part.sourcemessageid = NEW.id LOOP allText := allText || '' '' || currentRecord.textdata; END LOOP; allText := allText || '' '' || NEW.subject; INSERT INTO cks_messagetext (id, textdata) VALUES (NEW.id, allText); RETURN NEW; ENDIF; END; 'LANGUAGE plpgsql; Thank you for any help in advance. Jon Poulton jon@illumining.com