Re: Temp table exists test??

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Temp table exists test??
Дата
Msg-id 9763.1107487089@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Temp table exists test??  (Michael Guerin <guerin@rentec.com>)
Список pgsql-novice
Michael Guerin <guerin@rentec.com> writes:
> I'm trying to detect the existence of a temp table in a function for
> that connection.

Perhaps something like

select * from pg_class where relname = 'foo' and pg_table_is_visible(oid);

However this will potentially trigger on non-temp tables, if you have
any of matching names that are in your search path.  Dunno if that's a
problem for your application.

Another way is to look at current_schemas(), though you would need to
check whether the first entry is a temp schema or not (it isn't until
you've created at least one temp table):

regression=# select current_schemas(true);
   current_schemas
---------------------
 {pg_catalog,public}
(1 row)

regression=# create temp table foo(f1 int);
CREATE TABLE
regression=# select current_schemas(true);
        current_schemas
-------------------------------
 {pg_temp_1,pg_catalog,public}
(1 row)

regression=# select (current_schemas(true))[1];
 current_schemas
-----------------
 pg_temp_1
(1 row)

regression=#

            regards, tom lane

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Mike G."
Дата:
Сообщение: Re: how to generate printed output of queries
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: Temp table exists test??