Problem with inserting into a triggerable table; - Mailing list pgsql-general

From Anoop Rajendra
Subject Problem with inserting into a triggerable table;
Date
Msg-id Pine.OSF.4.58.0403251228470.31333@omega.uta.edu
Whole thread Raw
Responses Re: Problem with inserting into a triggerable table;
List 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

pgsql-general by date:

Previous
From: "Nilton Yudiro Ikezire"
Date:
Subject: Compiling
Next
From: Peter Lang
Date:
Subject: pg_dump "what if?"