?
Solved

dependency tree of tables in PostgreSQL

Posted on 2014-04-23
4
Medium Priority
?
1,464 Views
Last Modified: 2014-04-25
Hello Experts

how can I get the list of the postgresql tables in order of dependency tables.
Problem: I need to make a  migration routine of data from one oracle database to PostgreSQL. The data model is equal.
0
Comment
Question by:alcionebernardi
  • 2
4 Comments
 
LVL 3

Expert Comment

by:bayoubeast
ID: 40019058
In psql you could do something like this:

select '\\d+ '||table_schema||'.'||table_name
from information_schema.tables
order by table_schema,table_name;

Open in new window


And if you run the output from that back into psql that will list the dependencies for each table individually.  You'll probably want to add a where clause for the specific schema you want to look at so you don't get all the postgresql tables.

select '\\d+ '||table_schema||'.'||table_name
from information_schema.tables
where table_schema='public'
order by table_schema,table_name;

Open in new window


Is this kind of what you're looking for?  I'm not quite sure if there's a way to make a single list of tables ordered by dependency.
0
 

Author Comment

by:alcionebernardi
ID: 40020154
Hello,
    for example, two tables: d_m_transaction and m_transaction. d_m_transaction has references to m_transaction. I would like a sql that return the two tables in the following order

m_transaction
d_m_transaction

That way I could run the inserts without any violation of constraints

thanks
0
 
LVL 4

Accepted Solution

by:
Alex Matzinger earned 1500 total points
ID: 40020660
The easiest way to do this, is to drop the constraints/foreign keys from the tables in your postgres database, import the data (from oracle to postgres) and then re-add the constraints to the tables.  

Otherwise you will need to go by hand through each of your tables and list them in the order they will need to be.  There is no automatic way of listing tables by their constraints.
0
 
LVL 3

Expert Comment

by:bayoubeast
ID: 40020733
Yeah, that's probably the best way to do this.  If you're using ora2pg it has some options for this.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question