create function for trigger question

From: Barbara Lindsey <blindsey(at)cog(dot)ufl(dot)edu>
To: <pgsql-general(at)postgresql(dot)org>
Subject: create function for trigger question
Date: 2003-11-06 17:41:25
Message-ID: 1581.216.78.162.114.1068140485.squirrel@webmail.cog.ufl.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Carlos 2003-11-06 17:52:58 Install files for version 7.4
Previous Message Steve Wampler 2003-11-06 17:40:56 Default user after upgrade to 7.3?