"create temp table" in trigger in PostgreSQL

2

Is it possible to create an insert trigger in a "Table1" using "CREATE TEMP TABLE" in its structure and feed a "Table2"?

    
asked by anonymous 02.06.2015 / 23:33

1 answer

0

I do not quite understand what you want to do, but you can create temporary tables in your trigger.

Ex:

CREATE OR REPLACE FUNCTION f_table1_tbi() RETURNS TRIGGER AS $$

BEGIN     

    CREATE TEMPORARY TABLE table2 ON COMMIT DROP AS 
    SELECT NEW.*;

    RETURN NEW; 
END;

$$ LANGUAGE plpgsql;

CREATE TRIGGER table1_tbi BEFORE INSERT
ON table1 FOR EACH ROW EXECUTE PROCEDURE f_table1_tbi();

In this case, the temporary table table2 will be deleted when you commit.

    
23.11.2015 / 14:39