i try to create a plpgsql trigger for postgresql 8.3 which automatically partitions a table on before insert
by the id column
if the destination table doesnt exist it will be created, and the insert goes there
so i created the insert statement with the new table name like this
exec_insert := 'INSERT INTO '||TG_TABLE_SCHEMA||'.'||TG_RELNAME||'_'||destinationid||' VALUES('||NEW.*||')';
EXECUTE exec_insert;
resulting in the error:
ERROR: NEW used in query that is not in a rule
i have 2 questions:
- is it even possible to use NEW in EXECUTE or is there some mistake in the statement?
- if its just not possible, anyone knows how to get the values out of NEW so i can use them in the statement? the only thing which comes to my mind is using information_schema to retrieve column names for the main table and then try to access NEW’s values dynamically – which i also dont know how 🙁
thx
This setup works fine over here (version 8.4 and 9.0):