Re: debugging triggers - get original statement? - Mailing list pgsql-sql

From bricklen
Subject Re: debugging triggers - get original statement?
Date
Msg-id CAGrpgQ9j9JQ7=Ofgx=Ln7YK0NbRiKknPPzjzzVTMMxvWqEdq5Q@mail.gmail.com
Whole thread Raw
In response to Re: debugging triggers - get original statement?  (gmb <gmbouwer@gmail.com>)
List 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 by date:

Previous
From: gmb
Date:
Subject: Re: debugging triggers - get original statement?
Next
From: minsheng.bai
Date:
Subject: about running plpgsqlo.sql