Problem with inserting into a triggerable table;

Поиск
Список
Период
Сортировка
От Anoop Rajendra
Тема Problem with inserting into a triggerable table;
Дата
Msg-id Pine.OSF.4.58.0403251228470.31333@omega.uta.edu
обсуждение исходный текст
Ответы Re: Problem with inserting into a triggerable table;  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Список 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 по дате отправления:

Предыдущее
От: "Nilton Yudiro Ikezire"
Дата:
Сообщение: Compiling
Следующее
От: Peter Lang
Дата:
Сообщение: pg_dump "what if?"