Re: column names from temporary tables

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: column names from temporary tables
Дата
Msg-id 5828.1036768305@sss.pgh.pa.us
обсуждение исходный текст
Ответ на column names from temporary tables  ("Kabai József" <kabai@audiobox.hu>)
Список pgsql-general
"Kabai J�zsef" <kabai@audiobox.hu> writes:
> I know how to get column names from tables:
> select attname from pg_attribute where attrelid=(select oid from
> pg_class where relname='table1');
> but it does not work for temporary tables, because when creating it gets a system name like 'pg_temp_6410_1'

There is no good solution in pre-7.3 releases, because the mapping from
logical temp table name to actual table name is hidden inside the
backend.

In 7.3 temp tables actually have their user-given names.  (They don't
conflict with regular tables because they're in a different schema.)
This moves the problem from "how do I find the temp table name" to "how
do I find the temp schema name" --- but there are several possible
answers to that.  One nice way is to bypass the problem by using the
new regclass datatype:

select attname from pg_attribute where attrelid = 'table1'::regclass;

The regclass conversion produces essentially the same effect as your
subselect, ie, it gets the OID of table1 ... but the regclass input
converter uses your schema search path, so it will find the temp table
named 'table1' in preference to any other 'table1'.

So, come help beta-test 7.3 ... ;-)

            regards, tom lane

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

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: HA PostgreSQL
Следующее
От: Neil Conway
Дата:
Сообщение: Re: command