dbTalk Databases Forums  

How to get all tables+rows which have a foreignkey reference to arow

comp.databases.postgresql comp.databases.postgresql


Discuss How to get all tables+rows which have a foreignkey reference to arow in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thomas Guettler
 
Posts: n/a

Default How to get all tables+rows which have a foreignkey reference to arow - 04-29-2008 , 10:43 AM






Hi,

MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.

Any hints?

Thomas


--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM






Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #6  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #7  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #8  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #9  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey reference to a row - 04-30-2008 , 02:34 AM



Thomas Guettler <hv (AT) tbz-pariv (DOT) de> wrote:
Quote:
MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.
In that case you won't be able to have it in a query result in the fashion
you desire. Why do you want it in exactly that fashion?

Maybe a better way can be found if you tell us what you are trying to
achieve with that.

Yours,
Laurenz Albe


Reply With Quote
  #10  
Old   
Coniglio Sgabbiato
 
Posts: n/a

Default Re: How to get all tables+rows which have a foreignkey referenceto a row - 04-30-2008 , 02:50 AM



Thomas Guettler ha scritto:
Quote:
Hi,

MyTable has a primary key id, and this column is used in
many tables as foreign keys. How can you get all tables/rows
which point to a given id?

The result should be something like:

tablename | foreignkey column name | primary key value of referencing table

Unfortunately the third column is not always of the same type.

Any hints?

Thomas


look onto information_schema, there you have all the system tables you need.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.