How does this query work.....?

Поиск
Список
Период
Сортировка
Искать

How does this query work.....?

От:
RbrtBrn3@aol.com
Дата:
Hi, 

I am using the following query to find the attributes of a given table, and
their datatypes:

select typname,attname                           
from pg_class c, pg_attribute a,pg_type t
where relname = 'table_name' and
attrelid = c.oid and
atttypid = t.oid and
attnum > 0;

Can anybody explain how this query actually works - I cannot figure it.
Thanks in advance.

Rob Burne.

Re: How does this query work.....?

От:
Stephan Szabo <sszabo@megazone23.bigpanda.com>
Дата:

pg_class holds the relation information (tables, etc)
pg_attribute holds attribute information (attname), it  keeps the oid of the relation it's on in attrelid and the oid of the type as atttypid
pg_type holds type information (typname)

The attnum>0 is to limit the check to user attributes.
There are additional attributes (oid, xmin, etc...) 
defined on the tables that have attnum<0 and you usually
don't care about that.

On Fri, 9 Mar 2001 RbrtBrn3@aol.com wrote:

> Hi,
> 
> I am using the following query to find the attributes of a given table, and 
> their datatypes:
> 
> select typname,attname                           
> from pg_class c, pg_attribute a,pg_type t
> where relname = 'table_name' and
> attrelid = c.oid and
> atttypid = t.oid and
> attnum > 0;
> 
> Can anybody explain how this query actually works - I cannot figure it. 
> Thanks in advance.
> 
> Rob Burne.
> 


FAQ