How create SQL variable sentense in plpgsql?! - Mailing list pgsql-general

From Mikhail V. Majorov
Subject How create SQL variable sentense in plpgsql?!
Date
Msg-id 3A8970D0.80A6EB2A@ttn.ru
Whole thread Raw
List pgsql-general
Hi all!

I try to make multi-purpose trigger for make history off change in some
tables.
The main purpose is to do "INSERT INTO textcat(TG_NAME, '_history')
VALUES (OLD)".
Is it possible? I have all time error: ERROR:  parser: parse error at or
near "$1"

Below I type example of SQL command for this.

CREATE TABLE my_table1 (...);
CREATE TABLE my_table1_history () INHERITS (my_table1);

CREATE TABLE my_table2 (...);
CREATE TABLE my_table2_history () INHERITS (my_table2);

CREATE TABLE my_table3 (...);
CREATE TABLE my_table3_history () INHERITS (my_table3);

CREATE FUNCTION make_history() RETURNS opaque AS '
DECLARE
    dbname    text;
BEGIN
    dbname := textcat(TG_NAME, ''_history'');
    INSERT INTO dbname VALUES (OLD);
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ I have problem in this line :(
END;
' as LANGUAGE 'plpgsql';

CREATE TRIGGER history_of_my_table1 AFTER UPDATE OR DELETE
    ON my_table1 FOR EACH ROW
    EXECUTE PROCEDURE make_history();

CREATE TRIGGER history_of_my_table2 AFTER UPDATE OR DELETE
    ON my_table2 FOR EACH ROW
    EXECUTE PROCEDURE make_history();

CREATE TRIGGER history_of_my_table3 AFTER UPDATE OR DELETE
    ON my_table3 FOR EACH ROW
    EXECUTE PROCEDURE make_history();

Best regards,
Mikhail.

pgsql-general by date:

Previous
From: "PM"
Date:
Subject: News server not working?
Next
From: Bodoni Endre
Date:
Subject: Tuple is to big