pthurmond Posted September 4, 2007 Share Posted September 4, 2007 Hello, I am trying to do some database modeling of a Postgres db. I would like to create a script that can scour a given database and list all of the tables and their respective columns. In MySQL they have a "SHOW TABLES" command, but I have yet to find such a thing for Postgres. In the long run I would like to be able to visually model a db by running a php script. It may require using some other language with PHP to render it properly on the page. The visual model would include a visual representation of relations between tables. I have seen software for this but I can't afford to buy any and I am running on Mac OS X, so most applications for this won't work for my machine anyways. I can always try to take a dump file of the db, but I would prefer a way to dynamically update the model on the fly to represent the current db. Any ideas, suggestions, scripts I haven't found yet? Thanks, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/67959-database-modeling/ Share on other sites More sharing options...
btherl Posted September 5, 2007 Share Posted September 5, 2007 There's a bunch of system catalogs which provide this. These change a little with each major version of postgres. You can find a list here Of particular interest: SELECT * FROM pg_tables WHERE schemaname = 'public'; SELECT * FROM pg_database; SELECT * FROM pg_indexes WHERE schemaname = 'public'; SELECT * FROM pg_views WHERE schemaname = 'public'; There's also the pg_class table, which is global table containing just about everything. Those tables I listed above are actually views into pg_class joined with some auxiliary tables. Quote Link to comment https://forums.phpfreaks.com/topic/67959-database-modeling/#findComment-341691 Share on other sites More sharing options...
pthurmond Posted September 5, 2007 Author Share Posted September 5, 2007 Fantastic, that is exactly the kind of thing I am looking for. Eventually I will have to find a way to do this for other databases too because I want to build a class that can model multiple types of SQL databases. Currently I am working with a Postgres db, so I will write it for that db first. The hard part for me will be graphically rendering it and adding the ability for users to customize it for testing theoretical changes to the db. Looks like I am going to learn AJAX and probably a few other technologies. Thanks for the strong start. Quote Link to comment https://forums.phpfreaks.com/topic/67959-database-modeling/#findComment-341721 Share on other sites More sharing options...
Oldiesmann Posted September 6, 2007 Share Posted September 6, 2007 You might also find the Information Schema helpful Quote Link to comment https://forums.phpfreaks.com/topic/67959-database-modeling/#findComment-343316 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.