Re: debugging triggers - get original statement?

Поиск
Список
Период
Сортировка
От bricklen
Тема Re: debugging triggers - get original statement?
Дата
Msg-id CAGrpgQ9j9JQ7=Ofgx=Ln7YK0NbRiKknPPzjzzVTMMxvWqEdq5Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: debugging triggers - get original statement?  (gmb <gmbouwer@gmail.com>)
Список pgsql-sql

On Wed, Jan 15, 2014 at 3:30 AM, gmb <gmbouwer@gmail.com> wrote:

>Another way is: modify the trigger and write informations you need in
>a specific table. Not an elegant solution but...

Exactly what I had in mind, but I hoped to be able to log the original
statement as well .
In that way I can simulate the problem-causing transactions exactly in a
more controlled env by running the scripts as in the log table.

You can also make use of the RAISE functionality and output the statement to your logs.

Here's a quick demo

create table footest (
id serial primary key,
col1 text,
col2 text
);

create or replace function do_something() returns trigger as
$func$
begin
RAISE LOG '%',(ROW(NEW.*)::text);
RETURN NEW;
end;
$func$ language plpgsql;

CREATE TRIGGER footest_trg BEFORE INSERT ON footest FOR EACH ROW EXECUTE PROCEDURE do_something();

-- In the logs:
2014-01-15 07:24:09 PST ... LOG:  (1,test1,test2)
2014-01-15 07:24:09 PST ... [INSERT] STATEMENT:  insert into footest (col1,col2) values ('test1','test2');

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

Предыдущее
От: gmb
Дата:
Сообщение: Re: debugging triggers - get original statement?
Следующее
От: minsheng.bai
Дата:
Сообщение: about running plpgsqlo.sql