Обсуждение: traversing foreign key relationships between tables

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

traversing foreign key relationships between tables

От
Markus Wagner
Дата:
Hi,

I have the following problem.

There is a trigger event on a table T. Table t is linked through n
intermediate tables (mostly n = 0) to a primary master Table M.

What I need to do is find the entry in M which corresponds to the
triggered entry in T.

I think in pseudocode it would be like this:
S = set of foreign keys in my entry in T
while S is not empty{ get s from S find referenced table t for s if t = M then return s as primary key into M put all
foreignkeys in t into S}
 

My problem is:

How to identify the attributes in a table (in pg_attribute) which are
foreign keys into other tables and how to get the relids of these other
tables?

Thank you very much,

Markus