Re: column names from temporary tables

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kabai J zsef" <kabai(at)audiobox(dot)hu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: column names from temporary tables
Date: 2002-11-08 15:11:45
Message-ID: 5828.1036768305@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Kabai Jzsef" <kabai(at)audiobox(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Neil Conway 2002-11-08 15:14:32 Re: command
Previous Message Andrew Sullivan 2002-11-08 15:07:56 Re: HA PostgreSQL