problem with trigger function - Mailing list pgsql-general

From Susan Cassidy
Subject problem with trigger function
Date
Msg-id CAE3Q8on=r2hc+6pJ34C5mR_=JVgiiV5Z0_K1B23rLM7JnUdnFw@mail.gmail.com
Whole thread Raw
Responses Re: problem with trigger function  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: Offending My Tender Sensibilities -OR- OLTP on a Star Schema
Next
From: Adrian Klaver
Date:
Subject: Re: problem with trigger function