| От | Harald Fuchs |
|---|---|
| Тема | Finding FOREIGN KEY constraints via information_schema |
| Дата | |
| Msg-id | pumzruddyv.fsf@srv.protecting.net обсуждение исходный текст |
| Список | pgsql-general |
I'm trying to find out which columns of which tables reference which
columns of which tables by querying the information_schema. I found
the referencing columns in key_column_usage and the referenced columns
in constraint_column_usage - fine so far.
Now consider the following:
CREATE TABLE t1 (
id1 INT NOT NULL,
id2 INT NOT NULL,
PRIMARY KEY (id1, id2)
);
CREATE TABLE t2 (
id1 INT NOT NULL,
id2 INT NOT NULL,
CONSTRAINT t2_id_fk FOREIGN KEY (id1, id2) REFERENCES t1 (id1, id2)
);
PostgreSQL groks that, and pg_dump correctly generates
ALTER TABLE ONLY t2
ADD CONSTRAINT t2_id_fk FOREIGN KEY (id1, id2) REFERENCES t1(id1, id2);
My problem is that, while key_column_usage knows the ordinal_position,
constraint_column_usage doesn't. How can I find out that it's really
REFERENCES t1(id1, id2)
and not
REFERENCES t1(id2, id1)
instead?
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера