Search Postgresql Archives

Finding FOREIGN KEY constraints via information_schema

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
      message can get through to the mailing list cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux