Re: debugging triggers - get original statement?

From: bricklen <bricklen(at)gmail(dot)com>
To: gmb <gmbouwer(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: debugging triggers - get original statement?
Date: 2014-01-15 15:25:47
Message-ID: CAGrpgQ9j9JQ7=Ofgx=Ln7YK0NbRiKknPPzjzzVTMMxvWqEdq5Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jan 15, 2014 at 3:30 AM, gmb <gmbouwer(at)gmail(dot)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');

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message minsheng.bai 2014-01-16 08:02:08 about running plpgsqlo.sql
Previous Message gmb 2014-01-15 11:30:07 Re: debugging triggers - get original statement?