Thread: How to get table definition of a PostgreSQL table

How to get table definition of a PostgreSQL table

From
Sandeep Khandelwal
Date:
Hi.

I would like to get field's name, datatype of each field, length of each field and precision of each field of a
PostgreSQLtable. Please let me SQL query to get this information. 

Thanks,
Sandeep




Re: How to get table definition of a PostgreSQL table

From
Sean Davis
Date:
On Friday 27 October 2006 02:25, Sandeep Khandelwal wrote:
> Hi.
>
> I would like to get field's name, datatype of each field, length of each
> field and precision of each field of a PostgreSQL table. Please let me SQL
> query to get this information.

See these two chapters in the postgresql docs:

http://www.postgresql.org/docs/8.1/interactive/catalogs.html
http://www.postgresql.org/docs/8.1/interactive/information-schema.html

Each has advantages over the other.

Also, if you start psql with the flag --echo-hidden, when you do commands like 
\dt and \d+, psql will show you the sql it uses to produce that output.

Sean


Re: How to get table definition of a PostgreSQL table

From
Sandeep Khandelwal
Date:
Thank you so much Sean.
Sandeep


----- Original Message ----
From: Sean Davis <sdavis2@mail.nih.gov>
To: pgsql-interfaces@postgresql.org
Cc: Sandeep Khandelwal <sandeep_khandelwal27@yahoo.com>
Sent: Friday, October 27, 2006 4:23:18 PM
Subject: Re: [INTERFACES] How to get table definition of a PostgreSQL table


On Friday 27 October 2006 02:25, Sandeep Khandelwal wrote:
> Hi.
>
> I would like to get field's name, datatype of each field, length of each
> field and precision of each field of a PostgreSQL table. Please let me SQL
> query to get this information.

See these two chapters in the postgresql docs:

http://www.postgresql.org/docs/8.1/interactive/catalogs.html
http://www.postgresql.org/docs/8.1/interactive/information-schema.html

Each has advantages over the other.

Also, if you start psql with the flag --echo-hidden, when you do commands like
\dt and \d+, psql will show you the sql it uses to produce that output.

Sean