pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
A question relative to creating an audit table
6+ messages / 4 participants
[nested] [flat]

* A question relative to creating an audit table
@ 2020-02-27 21:28  stan <stanb@panix.com>
  0 siblings, 3 replies; 6+ messages in thread

From: stan @ 2020-02-27 21:28 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

I ma considering setting up a function, and triggers to put a record in an
audit table when certain tables are altered. I pretty much think I know how
to do this, with one exception.

Can a function, called by a trigger, determine what table it was called
for?

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A question relative to creating an audit table
@ 2020-02-27 21:30  Andrei Zhidenkov <andrei.zhidenkov@n26.com>
  parent: stan <stanb@panix.com>
  2 siblings, 1 reply; 6+ messages in thread

From: Andrei Zhidenkov @ 2020-02-27 21:30 UTC (permalink / raw)
  To: stan <stanb@panix.com>; +Cc: pgsql-general@lists.postgresql.org

Why not to pass TG_TABLE_SCHEMA and TG_TABLE_NAME in its arguments?

> On 27. Feb 2020, at 22:28, stan <stanb@panix.com> wrote:
> 
> I ma considering setting up a function, and triggers to put a record in an
> audit table when certain tables are altered. I pretty much think I know how
> to do this, with one exception.
> 
> Can a function, called by a trigger, determine what table it was called
> for?
> 
> -- 
> "They that would give up essential liberty for temporary safety deserve
> neither liberty nor safety."
> 						-- Benjamin Franklin
> 
> 






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A question relative to creating an audit table
@ 2020-02-27 21:35  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: stan <stanb@panix.com>
  2 siblings, 0 replies; 6+ messages in thread

From: Adrian Klaver @ 2020-02-27 21:35 UTC (permalink / raw)
  To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org

On 2/27/20 1:28 PM, stan wrote:
> I ma considering setting up a function, and triggers to put a record in an
> audit table when certain tables are altered. I pretty much think I know how
> to do this, with one exception.
> 
> Can a function, called by a trigger, determine what table it was called
> for?
> 

Asked and answered:

https://www.postgresql.org/message-id/CAKFQuwY=wXXLZBJMv5ULk4P4B5sF+fnZXWThp-UGERE-NxEb4w@mail.gmail...

-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A question relative to creating an audit table
@ 2020-02-27 22:53  Vik Fearing <vik@postgresfriends.org>
  parent: stan <stanb@panix.com>
  2 siblings, 0 replies; 6+ messages in thread

From: Vik Fearing @ 2020-02-27 22:53 UTC (permalink / raw)
  To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org

On 27/02/2020 22:28, stan wrote:
> I ma considering setting up a function, and triggers to put a record in an
> audit table when certain tables are altered. I pretty much think I know how
> to do this, with one exception.

There are extensions out there that deal with this for you.  Here is
one: https://github.com/xocolatl/periods/

> Can a function, called by a trigger, determine what table it was called
> for?

Yes.
-- 
Vik Fearing





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A question relative to creating an audit table
@ 2020-02-28 13:59  stan <stanb@panix.com>
  parent: Andrei Zhidenkov <andrei.zhidenkov@n26.com>
  0 siblings, 1 reply; 6+ messages in thread

From: stan @ 2020-02-28 13:59 UTC (permalink / raw)
  To: Andrei Zhidenkov <andrei.zhidenkov@n26.com>; +Cc: pgsql-general@lists.postgresql.org

On Thu, Feb 27, 2020 at 10:30:15PM +0100, Andrei Zhidenkov wrote:
> Why not to pass TG_TABLE_SCHEMA and TG_TABLE_NAME in its arguments?
> 
> > On 27. Feb 2020, at 22:28, stan <stanb@panix.com> wrote:
> > 
> > I ma considering setting up a function, and triggers to put a record in an
> > audit table when certain tables are altered. I pretty much think I know how
> > to do this, with one exception.
> > 
> > Can a function, called by a trigger, determine what table it was called
> > for?
> > 

I suppose I could do that. I have in mind a single function to accomplish the
audit log, but I will have to have unique triggers for each table. I was
just hoping not to have to do that. Are these values that I could read
automatically? Or do I have to hard code them?

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A question relative to creating an audit table
@ 2020-02-28 14:02  Andrei Zhidenkov <andrei.zhidenkov@n26.com>
  parent: stan <stanb@panix.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrei Zhidenkov @ 2020-02-28 14:02 UTC (permalink / raw)
  To: stan <stanb@panix.com>; +Cc: pgsql-general@lists.postgresql.org

Please, read chapter 43.10.1 of the PostgreSQL documentation (https://www.postgresql.org/docs/11/plpgsql-trigger.html <https://www.postgresql.org/docs/11/plpgsql-trigger.html;). Just to be sure we are on the same page.

> On 28. Feb 2020, at 14:59, stan <stanb@panix.com> wrote:
> 
> On Thu, Feb 27, 2020 at 10:30:15PM +0100, Andrei Zhidenkov wrote:
>> Why not to pass TG_TABLE_SCHEMA and TG_TABLE_NAME in its arguments?
>> 
>>> On 27. Feb 2020, at 22:28, stan <stanb@panix.com> wrote:
>>> 
>>> I ma considering setting up a function, and triggers to put a record in an
>>> audit table when certain tables are altered. I pretty much think I know how
>>> to do this, with one exception.
>>> 
>>> Can a function, called by a trigger, determine what table it was called
>>> for?
>>> 
> 
> I suppose I could do that. I have in mind a single function to accomplish the
> audit log, but I will have to have unique triggers for each table. I was
> just hoping not to have to do that. Are these values that I could read
> automatically? Or do I have to hard code them?
> 
> -- 
> "They that would give up essential liberty for temporary safety deserve
> neither liberty nor safety."
> 						-- Benjamin Franklin

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2020-02-28 14:02 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 21:28 A question relative to creating an audit table stan <stanb@panix.com>
2020-02-27 21:30 ` Andrei Zhidenkov <andrei.zhidenkov@n26.com>
2020-02-28 13:59   ` stan <stanb@panix.com>
2020-02-28 14:02     ` Andrei Zhidenkov <andrei.zhidenkov@n26.com>
2020-02-27 21:35 ` Adrian Klaver <adrian.klaver@aklaver.com>
2020-02-27 22:53 ` Vik Fearing <vik@postgresfriends.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox