create function for trigger question - Mailing list pgsql-general

From Barbara Lindsey
Subject create function for trigger question
Date
Msg-id 1581.216.78.162.114.1068140485.squirrel@webmail.cog.ufl.edu
Whole thread Raw
List pgsql-general
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






pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: SQL-question: returning the id of an insert querry
Next
From: Christopher Browne
Date:
Subject: Re: Optimiser desicion bringing system to its knees?