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

From: Moshe Jacobson <moshe(at)neadwerx(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: What's faster? BEGIN ... EXCEPTION or CREATE TEMP TABLE IF NOT EXISTS?
Date: 2012-10-01 13:36:13
Message-ID: CAJ4CxLkPASgDgL6GoBvUwdbYmQ6=gifrwY7_0SjAOu6Wh+idBg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.
Until now I have been using a permanent table to store the session
variables, but it has been difficult to wipe the data properly at the end
of the session.
So I have decided to try to implement them using temporary tables.

The problem now is that for every row now, I need to check for the
existence of the temporary table before I access it, in order to avoid
exceptions.
Either I can do all such accesses within a BEGIN...EXCEPTION block, or I
can precede any such accesses with CREATE TEMP TABLE IF NOT EXISTS.
Is one of these much faster than the other? Will I be slowing things down
inordinately by doing this for every row?

Thanks.

--
Moshe Jacobson
Nead Werx, Inc. | Senior Systems Engineer
2323 Cumberland Parkway, Suite 201 | Atlanta, GA 30339
moshe(at)neadwerx(dot)com | www.neadwerx.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-10-01 13:39:21 Re: pg_upgrade: out of memory
Previous Message Andrew Hastie 2012-10-01 11:51:28 Re: pg_upgrade: out of memory