Search Postgresql Archives

problem with trigger function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm having a problem with a trigger function.  I've been googling for over an hour, with no luck with my specific problem.

I get this error:
ERROR:  missing FROM-clause entry for table "new"
LINE 1: insert into metric_double_values_201203 values (NEW.metricID...
                                                        ^
QUERY:  insert into metric_double_values_201203 values (NEW.metricID, NEW.sourceID, NEW.timestamp, NEW.value, NEW.datetimeval)
CONTEXT:  PL/pgSQL function metric_double_insert_func() line 8 at EXECUTE statement


From this trigger function:

CREATE OR REPLACE FUNCTION metric_double_insert_func()
RETURNS TRIGGER AS $$
  DECLARE insert_sql text;
BEGIN
     insert_sql:='insert into metric_double_values_' || to_char(NEW.datetimeval,'YYYYMM') || ' values (NEW.metricID, NEW.sourceID, NEW.timestamp, NEW.value, NEW.datetimeval)';
    EXECUTE insert_sql using NEW;
    RETURN NULL;
END;
$$
LANGUAGE plpgsql;

DROP TRIGGER insert_metric_double_insert_trigger on metric_double_values;
CREATE TRIGGER insert_metric_double_insert_trigger
        BEFORE INSERT ON metric_double_values
        FOR EACH ROW EXECUTE PROCEDURE metric_double_insert_func();


This was an attempt at eliminating the error I got when trying to insert with values (NEW.*) using NEW:
ERROR:  missing FROM-clause entry for table "new"
LINE 1: insert into metric_double_values_201203 values (NEW.*)
                                                        ^
QUERY:  insert into metric_double_values_201203 values (NEW.*)
CONTEXT:  PL/pgSQL function metric_double_insert_func() line 7 at EXECUTE statement

I don't know what from clause it is talking about

This is a trigger for inserting rows into the proper partition table based on date.

Any help appreciated.

Thanks,
Susan

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux