Discuss Show databases, Show tables, Describe table in the PostgreSQL Help forum on Dev Shed. Show databases, Show tables, Describe table PostgreSQL Help forum discussing administration, SQL syntax, or other PostgreSQL-related topics. PostgreSQL provides enterprise level database functionality at open source prices.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 249
Time spent in forums: 43 m 2 sec
Reputation Power: 10
Show databases, Show tables, Describe table
I am a MySQL geek. I've been looking up and down the Internet for PostgreSQL's equivalent function to MySQL's show databases, show tables and describe tables.
Help is much appreciated.
__________________
I have yet to find the right way to do it.
Posts: 2,306
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 59
For a list of databases, from the command line, all you need to do is 'psql -l'. (Try 'psql --help' for the other options). From inside the psql monitor, just try '\l'.
If you want to get database-specific attributes, such as tables, views, etc... just try \? from the psql monitor, and you will get a list of nice functions. ('\dt' will list all tables, for example).
To get fields from a table unfortunately, there is no simple command. But, you can query the PostgreSQL internal tables such as pg_class for that info:
Code:
SELECT
a.attnum,
a.attname AS field,
t.typname AS type,
a.attlen AS length,
a.atttypmod AS lengthvar,
a.attnotnull AS notnull
FROM
pg_class c,
pg_attribute a,
pg_type t
WHERE
c.relname = 'your_table_name'
and a.attnum > 0
and a.attrelid = c.oid
and a.atttypid = t.oid
ORDER BY a.attnum
The benefit of this method is that you get a nice list of column names, type, length, etc... I use it in PHP all the time. Remember, for a real database such as PostgreSQL, all your database attributes and properties are available as data from the postgreSQL internal tables, using standard SELECT queries. Once you learn those, you have access to all the metadata you want.