<br><br><div><span class="gmail_quote">On 8/14/07, <b class="gmail_sendername">Kevin C. Smith</b> &lt;<a href="mailto:kevin@linuxsmith.com">kevin@linuxsmith.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&gt;<br>&gt; CREATE FUNCTION set_last_update() RETURNS opaque AS &#39;<br>&gt; BEGIN<br>&gt; NEW.last_updated:=now();<br>&gt; RETURN NEW;<br>&gt; END;<br>&gt; &#39; LANGUAGE &#39;plpgsql&#39;;<br>&gt;<br>&gt; CREATE TRIGGER set_last_update AFTER INSERT OR UPDATE ON people FOR EACH
<br>&gt; ROW<br>&gt; EXECUTE PROCEDURE set_last_update();<br>&gt;<br><br>Okay I see maybe two issues (disclaimer I don&#39;t know what the hell I&#39;m<br>talking<br>about).<br><br>Wouldn&#39;t a trigger AFTER insert or update become in infinite loop, and maybe
<br>postgresql therefore ignores it? Just a guess.</blockquote><div><br>I thought trigger updates were different, but I&nbsp; guess it&#39;s possible. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I also think that were you have &#39;opaque&#39; you need &#39;trigger&#39;.</blockquote><div><br><br>The &#39;trigger&#39; type caused the parser to complain.&nbsp; However, I&#39;ll try it again when I can.&nbsp; It&#39;s possible the other things I did caused &#39;trigger&#39; to be valid.&nbsp; But my guess is &#39;opaque&#39; works in 
7.1, but &#39;trigger&#39; was added later.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I tested this and it worked:<br><br>
<br>CREATE OR REPLACE FUNCTION set_last_update()<br>&nbsp;&nbsp;RETURNS &quot;trigger&quot; AS<br>BEGIN<br>&nbsp;&nbsp;NEW.last_updated = now();<br>&nbsp;&nbsp;RETURN NEW;<br>END;<br>&nbsp;&nbsp;LANGUAGE &#39;plpgsql&#39; VOLATILE;<br><br><br>CREATE TRIGGER set_last_update
<br>&nbsp;&nbsp;BEFORE INSERT OR UPDATE<br>&nbsp;&nbsp;ON test_table<br>&nbsp;&nbsp;FOR EACH ROW<br>&nbsp;&nbsp;EXECUTE PROCEDURE set_last_update();</blockquote><div><br><br>I chose AFTER because I didn&#39;t want the timestamp to be affected if for some reason the update failed.&nbsp; I also thought if it happened before the insert, what would it be updating, since the record didn&#39;t exist yet.
<br><br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Good luck<br><br>--<br>Kevin C. Smith<br><br>_______________________________________________
<br>Cialug mailing list<br><a href="mailto:Cialug@cialug.org">Cialug@cialug.org</a><br><a href="http://cialug.org/mailman/listinfo/cialug">http://cialug.org/mailman/listinfo/cialug</a><br></blockquote></div><br><br clear="all">
<br>-- <br>Tim