Re: Insert with pl/pgsql trigger

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Insert with pl/pgsql trigger
Дата
Msg-id 7638.1210173861@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Insert with pl/pgsql trigger  ("Woody Woodring" <george.woodring@iglass.net>)
Список pgsql-sql
"Woody Woodring" <george.woodring@iglass.net> writes:
> My trigger is :
> CREATE OR REPLACE FUNCTION log_cpe_health() RETURNS trigger AS '
>    DECLARE
>    BEGIN
>       -- Update last outage before inserting
>       EXECUTE ''INSERT INTO cpe_health_history VALUES '' || NEW;
>    END;
> ' LANGUAGE plpgsql;

That's never going to work because of quoting issues, and it wouldn't be
an efficient way if it did work (because of having to re-parse and
re-plan the INSERT each time).  And if it did act the way you are
imagining, it still wouldn't be a good way because you typically want
some additional columns in the log table, such as a timestamp.

In recent releases you can do it like this:
INSERT INTO cpe_health_history VALUES (NEW.*);

which can be extended to, eg,
INSERT INTO cpe_health_history VALUES (NEW.*, now());
        regards, tom lane


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: how to check if a point is contained in a polygon ?
Следующее
От: "Matthew T. O'Connor"
Дата:
Сообщение: Joining with result of a plpgsql function