Re: How relate pg_class to pg_constraint

Поиск
Список
Период
Сортировка
От Gregory Stark
Тема Re: How relate pg_class to pg_constraint
Дата
Msg-id 8763jxoj5k.fsf@oxford.xeocode.com
обсуждение исходный текст
Ответ на How relate pg_class to pg_constraint  (Bill Todd <pg@dbginc.com>)
Список pgsql-general
Bill Todd <pg@dbginc.com> writes:

> I need to join pg_class and pg_constraint to get information about constraints
> on a table. It appears that pg_constraint.conrelid is the foreign key but I do
> not see a relid column in pg_class. What column(s) define the relationship
> between these tables? Thanks.

There's a system column called "oid" on all the system tables which is the
primary key. It doesn't show up unless you explicitly list it in the target
list of the select.

So you need a join like WHERE pg_class.oid = conrelid

If all you need is the name to display for users then there's a convenience
type called regclass which you can use by doing "SELECT conrelid::regclass
from pg_constraint". There are similar regtype and a few others like it too.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's 24x7 Postgres support!

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

Предыдущее
От: Bill Todd
Дата:
Сообщение: Re: How relate pg_class to pg_constraint
Следующее
От: Mike Diehl
Дата:
Сообщение: Call volume query