Re: Re: What's faster? BEGIN ... EXCEPTION or CREATE TEMP TABLE IF NOT EXISTS?

From: Ivan Voras <ivoras(at)freebsd(dot)org>
To: Moshe Jacobson <moshe(at)neadwerx(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: What's faster? BEGIN ... EXCEPTION or CREATE TEMP TABLE IF NOT EXISTS?
Date: 2012-10-05 08:09:09
Message-ID: CAF-QHFVWFHpxovTnnm3uaFayBSZHV_c76D+OpQp=nvzCYiTRXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5 October 2012 04:53, Moshe Jacobson <moshe(at)neadwerx(dot)com> wrote:
> On Thu, Oct 4, 2012 at 6:12 AM, Ivan Voras <ivoras(at)freebsd(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2012-10-05 11:51:48 Re: Trajectory of a [Pg] DBA
Previous Message Craig Ringer 2012-10-05 07:06:53 Re: Moving from Java 1.5 to Java 1.6