X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 76E2052930 for ; Fri, 22 Jul 2005 16:56:43 -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 90132-02 for ; Fri, 22 Jul 2005 19:56:33 +0000 (GMT) Received: from hotmail.com (bay105-f29.bay105.hotmail.com [65.54.224.39]) by svr1.postgresql.org (Postfix) with ESMTP id 38DA352928 for ; Fri, 22 Jul 2005 16:56:32 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Fri, 22 Jul 2005 12:56:33 -0700 Message-ID: Received: from 65.54.224.200 by by105fd.bay105.hotmail.msn.com with HTTP; Fri, 22 Jul 2005 19:56:33 GMT X-Originating-IP: [65.54.224.200] X-Originating-Email: [mor4321@hotmail.com] X-Sender: mor4321@hotmail.com In-Reply-To: <42E148E0.9080809@PresiNET.com> From: "David Hofmann" To: BAnderson@PresiNET.com Cc: pgsql-sql@postgresql.org Subject: Re: Tigger Date: Fri, 22 Jul 2005 15:56:33 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 22 Jul 2005 19:56:33.0829 (UTC) FILETIME=[7608ED50:01C58EF7] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.729 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, FROM_ENDS_IN_NUMS, MSGID_FROM_MTA_HEADER, RCVD_IN_BL_SPAMCOP_NET X-Spam-Level: *** X-Archive-Number: 200507/203 X-Sequence-Number: 22181 It didn't error out, however the function didn't work. Specificly the if statement. I took out the if statement and it started updating, I put it back in and it fails to update. Not sure why. I've confirmed that the program not attempting to update the stamp_lastupdate field. Here what I end up with that worked. CREATE or REPLEACE FUNCTION session_update() RETURNS trigger AS ' BEGIN -- Check date exists NEW.stamp_lastupdate := ''now''; RETURN NEW; END; ' LANGUAGE plpgsql; CREATE TRIGGER session_update BEFORE INSERT OR UPDATE ON sessions FOR EACH ROW EXECUTE PROCEDURE session_update(); I appercated the help Bricklen. David >From: Bricklen Anderson >To: David Hofmann >CC: pgsql-sql@postgresql.org >Subject: Re: [SQL] Tigger >Date: Fri, 22 Jul 2005 12:28:32 -0700 > >David Hofmann wrote: > > I'm using 7.3. > > > >> From: Bricklen Anderson > >> To: David Hofmann > >> CC: pgsql-sql@postgresql.org > >> Subject: Re: [SQL] Tigger > >> Date: Fri, 22 Jul 2005 12:17:41 -0700 > >> > >> David Hofmann wrote: > >> > I've look throught the docs and from what I can see the bellow code > >> > should work, however I keep getting the error: > >> > > >> > ERROR: parser: parse error at or near "$" at character 53 > >> > > >> > CREATE FUNCTION session_update() RETURNS trigger AS $session_update$ > >> > BEGIN > >> > -- Check date exists > >> > IF NEW.stamp_lastupdate IS NULL THEN > >> > NEW.stamp_lastupdate := 'now'; > >> > END IF; > >> > RETURN NEW; > >> > END; > >> > > >> > $session_update$ LANGUAGE plpgsql; > >> > > >> > CREATE TRIGGER session_update BEFORE INSERT OR UPDATE ON sessions FOR > >> > EACH ROW EXECUTE PROCEDURE session_update(); > >> > > >> > > >> > Any help or suggestions of websites I should read would be >appercated. > >> > > >> > David > >> > >> Which version of postgresql are you using? I don't believe that the > >> "$" quoting > >> was available in older versions than 8 (or late 7?). > >I don't think that it worked then. Simple test: > >CREATE FUNCTION session_update() RETURNS trigger AS ' >BEGIN > -- Check date exists > IF NEW.stamp_lastupdate IS NULL THEN > NEW.stamp_lastupdate := ''now''; > END IF; > RETURN NEW; >END; >' LANGUAGE plpgsql; > >-- >_______________________________ > >This e-mail may be privileged and/or confidential, and the sender does >not waive any related rights and obligations. Any distribution, use or >copying of this e-mail or the information it contains by other than an >intended recipient is unauthorized. If you received this e-mail in >error, please advise me (by return e-mail or otherwise) immediately. >_______________________________ _________________________________________________________________ Don’t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/