Re: Tigger

From: "David Hofmann" <mor4321(at)hotmail(dot)com>
To: BAnderson(at)PresiNET(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Tigger
Date: 2005-07-22 19:56:33
Message-ID: BAY105-F2918BEA4FBD95B8992E06BBBC90@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 <BAnderson(at)PresiNET(dot)com>
>To: David Hofmann <mor4321(at)hotmail(dot)com>
>CC: pgsql-sql(at)postgresql(dot)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 <BAnderson(at)PresiNET(dot)com>
> >> To: David Hofmann <mor4321(at)hotmail(dot)com>
> >> CC: pgsql-sql(at)postgresql(dot)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.
>_______________________________

_________________________________________________________________
Dont just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

In response to

  • Re: Tigger at 2005-07-22 19:28:32 from Bricklen Anderson

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-07-22 23:38:58 Re: Error when using array variable
Previous Message Bricklen Anderson 2005-07-22 19:35:18 Re: Tigger