Re: stored function data structures - difficulty - Mailing list pgsql-general

From J.V.
Subject Re: stored function data structures - difficulty
Date
Msg-id 4ED51C17.6010200@gmail.com
Whole thread Raw
In response to Re: stored function data structures - difficulty  (Mike Blackwell <mike.blackwell@rrd.com>)
List pgsql-general
this is a ton of documentation to wade through, it literally would take weeks to go through, and many trials and errors, fiddling to get what I need (if I ever get that far).

Is there specific documentation / tutorial that will guide me on:

a way to programatically:
   1.  Given a table name, find all foreign key fields in the given table by field name (column name)
   2.  Given a single foreign key field name, programatically look up the corresponding reference table name and the reference primary key field

store this information in some data structure that I can iterate through? 

like I said before, given my deadlines, it would be much faster for me to simply hard code all of the data for 100 tables and put it in a data structure than figure out the query I need with the stack of documentation to sort through and find what I need.  I am simply looking for a data structure that can be used and a way to iterate through.  I just need to know if this is possible and an example.

On 11/21/2011 5:23 PM, Mike Blackwell wrote:
Take a look at http://www.postgresql.org/docs/9.1/interactive/information-schema.html and http://www.postgresql.org/docs/9.1/interactive/catalogs.html.  I think you'll find what you need.  The former is relatively stable between releases, while the latter has more detail but is subject to change.

I have use the system catalogs for several one time projects related to foreign keys, including checking which fks have associated indexes defined.

__________________________________________________________________________________
Mike Blackwell | Technical Analyst, Distribution Services/Rollout Management | RR Donnelley
1750 Wallace Ave | St Charles, IL 60174-3401
Office: 630.313.7818
Mike.Blackwell@rrd.com
http://www.rrdonnelley.com





On Mon, Nov 21, 2011 at 17:30, J.V. <jvsrvcs@gmail.com> wrote:

I cannot find a way to programatically:
   1.  Given a table name, find all foreign key fields in the given table by field name (column name)
   2.  Given a single foreign key field name, programatically look up the corresponding reference table name and the reference primary key field

so have thought of simply hard coding this (for 100 tables).

What Kind of data structure could I use that is available to me that would hold as the key the table name and from there be able to iterate through and get all foreign keys by field name and from there another inner loop that would give me another key/value pair of the table name (key) and the primary key (value) that corresponds to that foreign key?

I want to hard code all of this information into a data structure and iterate through at some point in another function.

Instead of discovering this programatically, I can manually look at each table / schema diagram and hard code it, but I really need one super structure that will hold as keys every table in the schema and be able to drill down that that tables foreign keys and from there further drill down to get the table name, primary key field in that table.

I have seen a number of structures that might work, but cannot find an example on how to actually use for what I need to do.  If you do have an idea of a structure, it would be great and awesome if I could be pointed to an actual working example that I could test in a sandbox first to understand how it works.

thanks


J.V.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: "J.V."
Date:
Subject: Re: stored function data structures - difficulty
Next
From: "Tyler Hains"
Date:
Subject: Query Optimizer makes a poor choice