Re: Way to identify the current session's temp tables within pg_class ?

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Way to identify the current session's temp tables within pg_class ?
Date: 2014-08-25 12:12:01
Message-ID: CAB7nPqSdneY5WHOTtMN2uOmDLwLxvaC=da03xXGq+44mBqa2-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Aug 25, 2014 at 7:48 PM, Marc Mamin <M(dot)Mamin(at)intershop(dot)de> wrote:
> Hello,
>
> When different sessions create temp tables with the same name:
> How can I identify the oid of the one created within the current session ?

You can use pg_my_temp_schema for this purpose. It returns the OID of
the schema where temporary objects are stored for a given session.
Note that this returns InvalidOid if no temporary objects are defined.
Here is an example:
=# select pg_my_temp_schema();
pg_my_temp_schema
-------------------
0
(1 row)
=# create temp table aa (a int);
CREATE TABLE
=# SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema();
nspname
-----------
pg_temp_4
(1 row)

Regards,
--
Michael

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sameer Thakur 2014-08-25 12:35:09 Using fmgr_hook
Previous Message hubert depesz lubaczewski 2014-08-25 11:37:08 Re: deadlock in single-row select-for-update + update scenario? How could it happen?