Dynamic auditing of data with PostgreSQL trigger

前端 未结 1 541
孤独总比滥情好
孤独总比滥情好 2021-01-26 18:59

I\'m interested in using the following audit mechanism in an existing PostgreSQL database.

http://wiki.postgresql.org/wiki/Audit_trigger

but, would like (if poss

相关标签:
1条回答
  • 2021-01-26 19:26

    You didn't mention your version of PostgreSQL, which is very important when writing answers to questions like this.

    If you're running PostgreSQL 9.0 or newer (or able to upgrade) you can use this approach as documented by Pavel:

    http://okbob.blogspot.com/2009/10/dynamic-access-to-record-fields-in.html

    In general, what you want is to reference a dynamically named field in a record-typed PL/PgSQL variable like 'NEW' or 'OLD'. This has historically been annoyingly hard, and is still awkward but is at least possible in 9.0.

    Your other alternative - which may be simpler - is to write your audit triggers in plperlu, where dynamic field references are trivial.

    0 讨论(0)
提交回复
热议问题