X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 907C23A545A for ; Mon, 24 Jan 2005 15:09:55 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 40085-09 for ; Mon, 24 Jan 2005 15:09:49 +0000 (GMT) Received: from rosemontschool.org (rosemont-sch.org [209.158.100.18]) by svr1.postgresql.org (Postfix) with ESMTP id C0B823A546F for ; Mon, 24 Jan 2005 15:09:49 +0000 (GMT) Received: by rosemontschool.org (Postfix, from userid 99) id BF2761B45FB; Mon, 24 Jan 2005 09:57:40 -0500 (EST) Received: from odyssey (rosemont-sch.org [209.158.100.18]) by rosemontschool.org (Postfix) with ESMTP id 9DA071B45F9 for ; Mon, 24 Jan 2005 09:57:38 -0500 (EST) Subject: Looking up table names by REFERENCES From: Steve Castellotti To: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary="=-JfpzofW1oP0zYcES2gNW" Date: Tue, 25 Jan 2005 04:09:09 +1300 Message-Id: <1106579349.746.8.camel@odyssey> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.555 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, HTML_20_30, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200501/229 X-Sequence-Number: 20017 --=-JfpzofW1oP0zYcES2gNW Content-Type: text/plain Content-Transfer-Encoding: 7bit Hello all. I'm trying to write a recursive procedure to allow me to handle some data backup routines and deal with conflicts when restoring from within the program. Essentially, what I'd like to be able to do is if a table called "image" has a column called "file_id" which references a column called "file_id" in another table called "file" I want to be able to determine that pragmatically. If I wanted to backup all of the information about images in the database, I would need to backup all of the information about the file(s) each image corresponds to. For instance, I can get a list of all (user) table names with: SELECT relname AS table_name, oid FROM pg_class WHERE NOT relname ~ 'pg_.*' AND NOT relname ~ 'pga_.*' AND NOT relname ~ '.*_pkey' AND NOT relname ~ '.*_id_key' ORDER BY relname; and I can get a list of column names and their types (for the "image" table) with: SELECT a.attname AS field, t.typname AS type FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = 'image' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid ORDER BY a.attnum; Surely there's a simple way I can trace REFERENCES in a particular column across tables? Any help would be most appreciated, especially if I could be cc'd directly. Cheers Steve Castellotti --=-JfpzofW1oP0zYcES2gNW Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit
    Hello all. I'm trying to write a recursive procedure to allow me to handle some data backup routines and deal with conflicts when restoring from within the program.

    Essentially, what I'd like to be able to do is if a table called "image" has a column called "file_id" which references a column called "file_id" in another table called "file" I want to be able to determine that pragmatically. If I wanted to backup all of the information about images in the database, I would need to backup all of the information about the file(s) each image corresponds to.

    For instance, I can get a list of all (user) table names with:

SELECT relname AS table_name, oid
FROM pg_class
WHERE NOT relname ~ 'pg_.*'
AND NOT relname ~ 'pga_.*'
AND NOT relname ~ '.*_pkey'
AND NOT relname ~ '.*_id_key'
ORDER BY relname;

and I can get a list of column names and their types (for the "image" table) with:

SELECT a.attname AS field, t.typname AS type
FROM pg_class c, pg_attribute a, pg_type t
WHERE c.relname = 'image' and a.attnum > 0
and a.attrelid = c.oid and a.atttypid = t.oid
ORDER BY a.attnum;


    Surely there's a simple way I can trace REFERENCES in a particular column across tables?


    Any help would be most appreciated, especially if I could be cc'd directly.


Cheers

Steve Castellotti --=-JfpzofW1oP0zYcES2gNW--