X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9D9FFD9A89 for ; Wed, 28 Sep 2005 14:35:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 54967-04 for ; Wed, 28 Sep 2005 17:35:10 +0000 (GMT) Received: from qproxy.gmail.com (qproxy.gmail.com [72.14.204.207]) by svr1.postgresql.org (Postfix) with ESMTP id B488CD9A84 for ; Wed, 28 Sep 2005 14:35:09 -0300 (ADT) Received: by qproxy.gmail.com with SMTP id c12so379767qbc for ; Wed, 28 Sep 2005 10:35:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=GrCm2wvJh1CcKe+6YZnwbAu2wtPaEqBvhSYWee+KAVsChQT4egIWbnkucFWgp8hMQrifPVUI/ZOoHbA9XqWpSKMDRiRqz2xztX/Pwbkdf2TJ+OA6VVj/ozRCBhXQf6/QcwaO0kOOoKS/kkWnaEuFWUS5/LxLJX16EVN4Rn0K7dc= Received: by 10.65.44.10 with SMTP id w10mr14036qbj; Wed, 28 Sep 2005 10:35:09 -0700 (PDT) Received: by 10.64.180.12 with HTTP; Wed, 28 Sep 2005 10:35:09 -0700 (PDT) Message-ID: Date: Wed, 28 Sep 2005 13:35:09 -0400 From: Ian Meyer Reply-To: Ian Meyer To: pgsql-sql@postgresql.org Subject: Problem with function and trigger... MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.231 required=5 tests=[RCVD_BY_IP=0.024, UPPERCASE_25_50=0.207] X-Spam-Level: X-Archive-Number: 200509/281 X-Sequence-Number: 22828 I have a function declared as such: CREATE OR REPLACE FUNCTION thread_sync() RETURNS trigger AS $$ BEGIN IF TG_OP =3D 'DELETE' AND OLD.deleted =3D FALSE THEN UPDATE member SET total_threads=3Dtotal_threads-1 WHERE id=3DOLD.member= _id; RETURN OLD; ELSEIF TG_OP =3D 'INSERT' THEN UPDATE member SET total_threads=3Dtotal_threads+1 WHERE id=3DNEW.member= _id; RETURN NEW; ELSEIF TG_OP =3D 'UPDATE' AND NEW.deleted =3D TRUE THEN UPDATE member SET total_threads=3Dtotal_threads-1 WHERE id=3DNEW.member= _id; RETURN NEW; ELSEIF TG_OP =3D 'UPDATE' AND NEW.deleted =3D FALSE THEN UPDATE member SET total_threads=3Dtotal_threads+1 WHERE id=3DNEW.member= _id; RETURN NEW; END IF; RETURN NULL; END; $$ LANGUAGE plpgsql; And the trigger for it: CREATE TRIGGER thread_sync AFTER INSERT OR DELETE OR UPDATE ON thread FOR EACH ROW EXECUTE PROCEDURE thread_sync(); creating the function works fine, as well as creating the trigger, but when I go to insert a row, I get the following message: bcodev=3D> insert into thread (member_id,subject,category_id,last_member_id) values (1,'hi there this is a test',1,1); ERROR: record "old" is not assigned yet DETAIL: The tuple structure of a not-yet-assigned record is indeterminate. CONTEXT: PL/pgSQL function "thread_sync" line 2 at if What am I failing to understand with this?