Обсуждение: Re: System catalog and identifying

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

Re: System catalog and identifying

От
ville80@salo.salonseutu.fi (9902468)
Дата:
I got the solution to that problem a few moments after I had posted
the message...

If one has to identify users colums from a table without knowing their
names, use this approach:

In system catalog pg_attribute you have a description of each column,
and attnum identifies if column is a system column or not.If column is
a systemn column it's attnum is negative, if user column, positive.

So to get all user columns from table which attrelid is 25217 use the
following clause:

select attname from pg_attribute where attrelid = '25217' and attnum >
'0';

You can fetch attrelid like this:

select relfilenode from pg_class where relname =
'your_table_name_here';

Now, how one can tell if a column is the primary key column of the
table?

If you know please respond...

Thanks

-9902468