Re: trouble with trigger/function??? - Mailing list pgsql-general

From Nelson Ferreira Jr
Subject Re: trouble with trigger/function???
Date
Msg-id 39D9CCCE.66F720A0@radix.com.br
Whole thread Raw
In response to trouble with trigger/function???  ("chris markiewicz" <cmarkiew@commnav.com>)
Responses RE: trouble with trigger/function???  ("chris markiewicz" <cmarkiew@commnav.com>)
Re: trouble with trigger/function???  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
      Hi,

      Triggers cannot be writen in SQL. I suggest you use PL/PGSQL instead. In
fact you can use any server-side language, except SQL.
      The return type of the function must be OPAQUE, it means that the NEW
variable is returned  (NEW represents the row that is being inserted and so
fired the trigger)

                                                                         Nelson

chris markiewicz wrote:

> hello.
>
> i have been trying to create a trigger or trigger/function combination but i
> have so far been unsuccessful.  my task is simple, when someone inserts a
> row in the PERSON table, create a row in the RESOURCE table (note that i
> have to pass parameters).  details below...
>
> first, the basic procedure and trigger are shown here:
>
> CREATE FUNCTION sp_person_resource() RETURNS bool
>     AS 'insert into resource(rid, name, type, desc) values (1905, ''chris'',
> ''person'', ''blah''); select true;'
>     LANGUAGE 'sql';
>
> CREATE TRIGGER trig_person_resource BEFORE INSERT ON person
>     FOR EACH ROW EXECUTE PROCEDURE sp_person_resource();
>
> i do not know what to use for a return type (i don't really need to return
> anything).  but when i try to write a trigger to call that fn, it tells me
> that the fn must return opaque...i modify my proc but it tells me that "sql
> fns cannot return type opaque."
>
> what's going on?  and a side question, what is opaque?
>
> thanks
> chris


pgsql-general by date:

Previous
From: Marcin Mazurek
Date:
Subject: Re: pg_dump on view
Next
From: "Poul L. Christiansen"
Date:
Subject: Re: full text indexing