Quantcast
Channel: House 9
Viewing all articles
Browse latest Browse all 29

Get table and column information in postgres

$
0
0
Use the information_schema catalog - http://www.postgresql.org/docs/9.1/static/information-schema.html

Get table and columns from the public schema




This can be useful, maybe you want to auto generate some text that creates foreign keys based on a naming convention - for instance let's say we have a ruby/rails method called make_fk_unless_exists




The 'code' column would render something like

make_fk_unless_exists :projects, :milestone_id, :milestones
make_fk_unless_exists :tasks, :project_id, :projects
...



Viewing all articles
Browse latest Browse all 29

Trending Articles