Обсуждение: create function for trigger question

Поиск
Список
Период
Сортировка

create function for trigger question

От
Barbara Lindsey
Дата:
I am a postgres newbie.

I am trying to create a trigger that will put a copy of a record into a
backup table before update or delete. As I understand it, in order to do
this I must have a function created to do this task.
The function I am trying to create is as follows:

CREATE FUNCTION customer_bak_proc(integer)  RETURNS boolean as
'INSERT INTO customer_bak  (SELECT * from customer where id = $1 )'
LANGUAGE 'SQL';

Whenever I try to create this function, I get an error on the return type,
as follows:
ERROR:  function declared to return boolean, but final statement is not a
SELECT

I have tried using text, integer, opaque, NULL, 0, 1.
And I have tried omitting the "RETURNS" clause altogether, but none of
these works.

What is the return data type of an SQL INSERT statement? I think that
would work (?), but I have not been able to find this in any of the
documentation.

Has anyone else successfully written a function to do an insert?
Has anyone else written a trigger to accomplish this kind of task?
Perhaps I am taking the wrong approach...
Thank you for any help.
Barb Lindsey