Hello there
I have been trying to generate a dynamic querystring thats to be executed inside a trigger function and every time I use NEW.* pl/pgsql throws an error saying 'column * does not exist'.
Since this did not work I tried to alter it a bit by explicitly specifying the column names like
It works fine for non-character columns, I tried to insert values like "INSERT into matrix(id,accep t,day,month,yea r) values (4,'YES',3,3,20 07)", but pl/pgsql throws an error for 'YES'. This is because it ignores the quotes when I specify the column names explicitly.
Could anyone please help me out with this? And if you are wondering why the table names are different, they are partitioned tables so there is a child-parent relationship between them.
Any help on this issue would be appreciated!
Cheers
I have been trying to generate a dynamic querystring thats to be executed inside a trigger function and every time I use NEW.* pl/pgsql throws an error saying 'column * does not exist'.
Code:
CREATE OR REPLACE FUNCTION matrix_test_insert_trigger()
RETURNS trigger AS
$$
BEGIN
EXECUTE 'INSERT INTO matrix_' || NEW.month || '(id,accept,day,month,year) values ' || NEW.*;
RETURN NULL;
END;
$$
LANGUAGE 'plpgsql'
Code:
CREATE OR REPLACE FUNCTION matrix_test_insert_trigger()
RETURNS trigger AS
$$
BEGIN
EXECUTE 'INSERT INTO matrix_' || NEW.month || '(id,accept,day,month,year) values ' || (NEW.id,NEW.accept,NEW.day,NEW.month,NEW.year);
RETURN NULL;
END;
$$
LANGUAGE 'plpgsql'
It works fine for non-character columns, I tried to insert values like "INSERT into matrix(id,accep t,day,month,yea r) values (4,'YES',3,3,20 07)", but pl/pgsql throws an error for 'YES'. This is because it ignores the quotes when I specify the column names explicitly.
Could anyone please help me out with this? And if you are wondering why the table names are different, they are partitioned tables so there is a child-parent relationship between them.
Any help on this issue would be appreciated!
Cheers
Comment