Search Postgresql Archives

Triggers and User Defined Trigger Functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 '
INSERT INTO Archive_MyTable
(
	ID,
	MyData
)
VALUES
(
	OLD.ID,
	OLD.MyData
);
RETURN OLD;
' LANGUAGE SQL;

This gives me one of the following errors:
ERROR:  SQL functions cannot return type opaque
ERROR:  SQL functions cannot return type "trigger"
ERROR:  type "heaptuple" does not exist

What type should my function be returning?
ERROR: type

Then I'd like to do the following:

CREATE TRIGGER MyTable_Trigger_DELETE BEFORE DELETE ON MyTable
FOR EACH ROW
EXECUTE PROCEDURE MyTable_Trigger_DELETE();

Can I create a trigger function like this? If not, what are my options WRT alternatives?

Many thanks.

Gordan

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux