On 5 October 2012 04:53, Moshe Jacobson <moshe@neadwerx.com> wrote:
> On Thu, Oct 4, 2012 at 6:12 AM, Ivan Voras <ivoras@freebsd.org> wrote:
>>
>> On 01/10/2012 15:36, Moshe Jacobson wrote:
>> > I am working on an audit logging trigger that gets called for every row
>> > inserted, updated or deleted on any table.
>> > For this, I need to store a couple of temporary session variables such
>> > as
>> > the ID of the user performing the change, which can be set at the start
>> > of
>> > the session.
>>
>> Do you know about session variables?
>> The major benefit here is that it doesn't touch the table engines,
>> temporary or not.
>
> This sounds incredibly useful. Why have I not heard of this until today??
> In your example you still had to use a BEGIN...EXCEPTION block. Is that
> faster than a create temp table?
I think I can make a fairly educated guess that catching exceptions
while dealing with session variables should be much, much faster than
creating any kind of a table :)
Besides, from what you said, you will ensure on the app level that the
session variable is set sometime close to when you open a connection
to Pg, so the "catch" part of the exception block will probably not
run at all.