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 22:05:56
Message-ID: 1882.216.78.162.114.1068156356.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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig O'Shannessy 2003-11-06 22:52:09 Optimiser desicion bringing system to its knees?
Previous Message Boris Popov 2003-11-06 22:02:14 Re: pid of current session?