From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Gordan Bobic <gordan(at)bobich(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Triggers and User Defined Trigger Functions |
Date: | 2005-03-09 12:25:56 |
Message-ID: | 422EEB54.4080401@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Gordan Bobic wrote:
> Hi,
>
> I'm trying to figure out how to do this from the documentation, but I
> can't figure it out. :-(
>
> Here is what I'm trying to do:
>
> CREATE TABLE MyTable
> (
> ID bigserial unique,
> MyData char(255),
> PRIMARY KEY (ID)
> );
>
> CREATE TABLE Archive_MyTable
> (
> ID bigserial unique,
> MyData char(255),
> PRIMARY KEY (ID)
> );
>
> CREATE FUNCTION MyTable_Trigger_DELETE()
> RETURNS ???opaque/trigger/HeapTuple??? AS '
RETURNS TRIGGER
> INSERT INTO Archive_MyTable
> (
> ID,
> MyData
> )
> VALUES
> (
> OLD.ID,
> OLD.MyData
> );
> RETURN OLD;
> ' LANGUAGE SQL;
You can't use SQL as the target language, it has to be one of the
procedural languages (e.g. plpgsql)
Something like:
CREATE FUNCTION my_trig_fn() RETURNS trigger AS '
BEGIN
INSERT INTO archive_mytable (id,mydata) VALUES (OLD.id, OLD.mydata);
RETURN OLD;
END;
' LANGUAGE plpgsql;
You can also use many other languages for functions - tcl/perl/python (I
think)/java etc. Check your language of choice supports triggers though.
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Pruteanu Dragos | 2005-03-09 12:37:41 | out of memory problem |
Previous Message | Stanislaw Tristan | 2005-03-09 11:19:11 | PL/Java vs PL/pgSQL |