Problem with inserting into a triggerable table;

From: Anoop Rajendra <axr3845(at)omega(dot)uta(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Problem with inserting into a triggerable table;
Date: 2004-03-25 18:36:58
Message-ID: Pine.OSF.4.58.0403251228470.31333@omega.uta.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, I was having some problems with inserting into a table with a trigger
function attached.

My code is shown below -
CREATE OR REPLACE FUNCTION update_tv_prefs() RETURNS trigger AS '
BEGIN
SELECT * FROM tvprefs WHERE ch_number = NEW.id AND time_of_day =
get_time() as X;
IF NOT FOUND THEN
INSERT INTO tvprefs values(NEW.id, get_time(),1);
ELSE
UPDATE tvprefs SET counter = counter+1 WHERE ch_number =
NEW.id;
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER update_tv AFTER INSERT on tv FOR EACH ROW EXECUTE PROCEDURE
update_tv_prefs();

Here, I dont have problems creating either the trigger or the function.
Nor did I have any problems with the language before. I wrote another
function with pretty much the same syntax ( not a trigger function though)
and I didnt get any errors.
But when I try to insert into the TV table, I get a error telling me -

ERROR: syntax error at or near "as" at character 76
CONTEXT: PL/pgSQL function "update_tv_prefs" line 2 at SQL statement

I was just wondering what I was doing wrong.

Please email a copy of your message to this address, as I am not
subscribed to the list.

Thanks a lot.

Anoop

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2004-03-25 18:37:01 Re: 7.4.2 on Solaris 9 - Error
Previous Message Shelby Cain 2004-03-25 18:23:28 Re: Memory usage during vacuum