Re: Simplifying identification of temporary tables

From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Simplifying identification of temporary tables
Date: 2005-07-14 18:09:12
Message-ID: 6EE64EF3AB31D5448D0007DD34EEB3415C2D9A@Herge.rcsinc.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Currently, the recommended way to ask "have I already created a temp
> table named foo" is something like
>
> select * from pg_class
> where relname = 'foo' and pg_table_is_visible(oid);
>
> If there's a possibility that a regular table named 'foo' exists,
> then this isn't good enough and you have to resort to
>
> select *
> from pg_class c join pg_namespace n on n.oid = c.relnamespace
> where relname = 'foo' and nspname like 'pg_temp_%' and
> pg_table_is_visible(c.oid)

Well now that we have savepoints you have another approach. In
non-dynamic pl/pgsql functions my preferred method is to probe the table
via normal sql and recreate it on the appropriate exception.

That said, I think what you are proposing is good since it causes less
log pollution. Although I would prefer to return the name of the
namespace, not the oid, or just go right to the point and create
function accepting temp table name and returning bool. That way the oid
is abstracted into the function.

Merlin

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-07-14 18:12:52 Re: Autovacuum loose ends
Previous Message Tom Lane 2005-07-14 18:04:58 Re: Autovacuum loose ends