Rows are repeating by the trigger function

Поиск
Список
Период
Сортировка
От Kiran
Тема Rows are repeating by the trigger function
Дата
Msg-id CAJfd1U4rNFxjrTxZ-BjPMtAoyXTCgo3j6Pa4_8zj0xT4O6Q5Tw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Rows are repeating by the trigger function  (Alban Hertroys <haramrae@gmail.com>)
Re: Rows are repeating by the trigger function  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
Dear Folks,

I have a  table cf_question with 31 rows.
I want to insert/update another table cf_user_question_link  when cf_question table is inserted/updated with row(s). 
I have written trigger function for this as follows. 


CREATE FUNCTION user_question_link() RETURNS trigger AS
$user_question_link$
begin
SET search_path TO monolith;
INSERT INTO
cf_user_question_link(cf_user_id,cf_question_id)
VALUES(NEW.user_id,NEW.cf_question_id);
RETURN NEW;
end;
$user_question_link$
LANGUAGE plpgsql 
COST 100;


/* Call the trigger function */

CREATE TRIGGER insert_user_question_link AFTER INSERT OR UPDATE
ON monolith.cf_question
FOR EACH ROW EXECUTE PROCEDURE user_question_link();


Problem: The cf_user_question_link gets inserted with 94 rows instead of 31 rows. The 31 rows are repeated 3 times 
                 I tried dropping the trigger function and recreating it but with the same 94 rows in the table.

It would be great if any from the forum point to me where I am doing wrong.

regards
Kiran

В списке pgsql-general по дате отправления:

Предыдущее
От: Samuel Williams
Дата:
Сообщение: Re: initdb createuser commands
Следующее
От: Evan Martin
Дата:
Сообщение: Way to quickly detect if database tables/columns/etc. were modified?