i have a trigger for a certain table in my database,
CREATE TRIGGER trig_trig
AFTER DELETE OR UPDATE OR INSERT ON A
FOR EACH ROW
EXECUTE PROCEDURE trig_func();
anyway.. i want to create a copy of the old table, and then run some tests on the difference between the 2.
to copy a table is easy , simply i do :
CREATE OR REPLACE FUNCTION trig_func() RETURNS TRIGGER AS $$
BEGIN
CREATE TABLE temp as(SELECT * FROM A);
DROP TABLE temp;
return new;
END;
$$ LANGUAGE plpgsql;
but i want to get the version before and after the change. this will simply give me one of them
i tried:
CREATE TABLE temp as(SELECT * FROM OLD.A);
or
CREATE TABLE temp as(SELECT * FROM NEW.A);
but i just get an error.
does anyone know how to do it?
thanx.
matt
OLDandNEWare pseudo-records. Rows, not tables, you can’t select from them.I can hard suggest how to do it, because it is not clear what exactly your intention is. Maybe you want to create one copy
BEFOREthe operation and oneAFTER? In separate triggers?