checking for temp tables information_schema vs. EXCEPTION

Поиск
Список
Период
Сортировка
От Ivan Sergio Borgonovo
Тема checking for temp tables information_schema vs. EXCEPTION
Дата
Msg-id 20090721102115.51ac4f31@dawn.webthatworks.it
обсуждение исходный текст
Список pgsql-general
I didn't find a definitive answer on how to check for the existence
of a temporary table.

I did a not scientific test to see if I could see a temp table from
another connection in the information_schema... and I can't.

The schema system is more direct (so cleaner) but it seems to rely on
some "behind the scene trick" I don't fully understand.

I could do a list of insane things like:

begin;
create or replace function tt_test() returns void as
$$
declare
    sch varchar(128);
begin
  create temp table pippo (i int);
  select into sch table_schema from information_schema.tables
  where
  table_name='pippo' and
  table_type='LOCAL TEMPORARY';

  execute 'create table ' || sch || '.pippo (i int);'; -- FAIL
  execute 'create schema ' || sch || ';'; -- NOT TESTED
  create table pippo (i int);  -- SUCCEDE

  create temp table zzz as
    select * from information_schema.tables
    where
    table_name='pippo';

  return;
end;
$$ language plpgsql;
select * from tt_test();
commit;
select * from zzz limit 10;

It looks like an invisible search path is added.
How temp schema name are obtained? Is there any place in the manual
that say that pg_temp_.* is a "reserved schema pattern"?

I didn't test but the EXCEPTION method may miss the difference
between the temp table and the permanent table. And schema
qualifying the temp table requires some further extra step.
So EXCEPTION method doesn't look safe.

Does EXCEPTION have some other hidden cost? Just for curiosity.

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


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

Предыдущее
От: Janning Vygen
Дата:
Сообщение: Re: suggestion: log_statement = sample
Следующее
От: Bjørn T Johansen
Дата:
Сообщение: ERROR: could not access status of transaction 2495690984