To brief the question, I have a table named partitions_info
which maintains the details of all other tables I am using.
Columns of partitions_info
are tablename
, starttime
, endtime
I have compiled following trigger for selecting a particular table name from partitions_info
table (schema shown above) based on some conditions.
I store the table name into a variable table_name
. Now how can I insert some values into the table which is stored in variable table_name
?
CREATE OR REPLACE FUNCTION emp_fun()
RETURNS TRIGGER AS
$$
DECLARE
table_name varchar(65);
BEGIN
SELECT tablename FROM partitions_info INTO table_name WHERE starttime<'2015-12-04 14:23:56' AND endtime>'2015-12-04 14:23:56';
IF table_name IS NULL THEN
INSERT INTO default_table VALUES (NEW.*);
END IF;
# Here I wanted to insert into table name which is stored in variable whose name is stored in "table_name" variable declared above
RETURN NEW;
END;
$$
LANGUAGE plpgsql;