471,073 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

About table schema

Hi, does anyone know how to get the schema information
of a table. More specifically, I would like to know

1. which field(s) are primary keys?
2. the data type of each field of a table?
3. If a field is a foreign key, what field/table it
is referring to.

Thanks.

Wei

__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #1
6 1311
Am Mittwoch, 26. Mai 2004 00:36 schrieb Wei Shi:
Hi, does anyone know how to get the schema information
of a table. More specifically, I would like to know

1. which field(s) are primary keys?
2. the data type of each field of a table?
3. If a field is a foreign key, what field/table it
is referring to.


connect to your database with 'psql' and type

\d tablename

which gives you all information you asked for. Type \? for a list of other
commands within psql and take a look at 'man psql'

kind regards,
janning

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
Is there a function interface to get this information
other than from "psql" comman line interface?

Thanks.

Wei

--- Janning Vygen <vy***@gmx.de> wrote:
Am Mittwoch, 26. Mai 2004 00:36 schrieb Wei Shi:
Hi, does anyone know how to get the schema

information
of a table. More specifically, I would like to

know

1. which field(s) are primary keys?
2. the data type of each field of a table?
3. If a field is a foreign key, what field/table

it
is referring to.


connect to your database with 'psql' and type

\d tablename

which gives you all information you asked for. Type
\? for a list of other
commands within psql and take a look at 'man psql'

kind regards,
janning

---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to

ma*******@postgresql.org

__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
Wei Shi wrote:
Is there a function interface to get this information
other than from "psql" comman line interface?


If you start psql with the '-E' switch, you'll see the queries it
generates to display the meta-data associated with the '\' command
you issue.

You may also query the tables and views in the information_schema
for what you want.

Mike Mascari
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #4
This is great. Thanks.

Wei

--- Mike Mascari <ma*****@mascari.com> wrote:
Wei Shi wrote:
Is there a function interface to get this

information
other than from "psql" comman line interface?


If you start psql with the '-E' switch, you'll see
the queries it
generates to display the meta-data associated with
the '\' command
you issue.

You may also query the tables and views in the
information_schema
for what you want.

Mike Mascari
---------------------------(end of
broadcast)---------------------------
TIP 2: you can get off all lists at once with the
unregister command
(send "unregister YourEmailAddressHere" to

ma*******@postgresql.org)

__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #5
Wei Shi wrote:
This is great. Thanks.


There is also the information schema in 7.4, e.g. "SELECT * FROM
information_schema.tables"

There's not as much detail there, but it's supposed to be standard
across different database systems.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #6
Wei Shi wrote:
Hi, does anyone know how to get the schema information
of a table. More specifically, I would like to know

1. which field(s) are primary keys?
2. the data type of each field of a table?
3. If a field is a foreign key, what field/table it
is referring to.


Use the information schema views.
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Firehawk® | last post: by
1 post views Thread by felix-lists-pgsql | last post: by
7 posts views Thread by slitvinov | last post: by
1 post views Thread by LurfysMa | last post: by
7 posts views Thread by Serge Rielau | last post: by
3 posts views Thread by Mike Husler | last post: by
3 posts views Thread by Michel Esber | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.