PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help
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.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 3rd, 2002, 02:12 AM
genedavinci's Avatar
genedavinci genedavinci is offline
I am still learning
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Kuala Lumpur, Malaysia
Posts: 249 genedavinci User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

www.genedavinci.com

Reply With Quote
  #2  
Old July 3rd, 2002, 05:49 PM
Ted Striker Ted Striker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 409 Ted Striker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
Red face

I cheat and use the Postgres admin plugin on Webmin.

http://www.webmin.com/

Reply With Quote
  #3  
Old July 3rd, 2002, 06:23 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
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.

There are all kinds of great tools to administrate PostgreSQL, from phpPgAdmin to PgAdmin for Windows. Check out http://techdocs.postgresql.org/ and http://techdocs.postgresql.org/oresources.php
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #4  
Old July 22nd, 2002, 04:02 AM
kimeros kimeros is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Melbourne, Australia
Posts: 3 kimeros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 2 sec
Reputation Power: 0
Hi,

I understand that this question/answer was posted a while ago but for the benefit of people like myself who search the past questions -

You can view the fields of a table without having to query the pg_class .. tables.

---------------------------------

kimstest=> \d addressbook
+-------+---------------+--------+
| Filed | Type | Length |
+-------+---------------+--------+
| code | int4 not null | 4 |
| name | char() | 24 |
| addr | varchar() | 32 |
+-------+---------------+--------+

Reply With Quote
  #5  
Old July 22nd, 2002, 10:50 AM
ultraslacker's Avatar
ultraslacker ultraslacker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 56 ultraslacker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
\d ~= desc

\dt Show Tables
\dT list datatypes
\df list functions
\di list indexes
\dv list views

You can use wildcards with \d, e.g. \df pg_* will show all functions beginning "pg_" Use specific objects name with \d to get the details.

All this is explained in \?

Reply With Quote
  #6  
Old October 20th, 2004, 11:56 AM
shrirang shrirang is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 shrirang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Describe table in postgres

Try \d tablename at the psql prompt

Reply With Quote
  #7  
Old October 20th, 2004, 03:43 PM
metaBarf metaBarf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 373 metaBarf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 49 m 6 sec
Reputation Power: 9
wow, how did you dig up this baby?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Show databases, Show tables, Describe table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


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

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap