How to view the list of tables?

Started by Konstantin Danilovabout 21 years ago6 messagesgeneral
Jump to latest
#1Konstantin Danilov
danilov_konst@list.ru

Hello, list!
I need to view the list of tables in a database. In MySQL I can do it with the command "SHOW TABLES". What about PostgreSQL?
Can I also see somehow the datatypes of tables' fields?
Konstantin

#2Dick Davies
rasputnik@hellooperator.net
In reply to: Konstantin Danilov (#1)
Re: How to view the list of tables?

* Konstantin Danilov <danilov_konst@list.ru> [0222 10:22]:

Hello, list!
I need to view the list of tables in a database. In MySQL I can do it with the command "SHOW TABLES". What about PostgreSQL?
Can I also see somehow the datatypes of tables' fields?

\dt in psjl lists tables

( \d gives you things like sequences as well)

\d tablename shows its layout.

--
'Tempers are wearing thin. Let's hope some robot doesn't kill everybody.'
-- Bender
Rasputin :: Jack of All Trades - Master of Nuns

#3Richard Huxton
dev@archonet.com
In reply to: Konstantin Danilov (#1)
Re: How to view the list of tables?

Konstantin Danilov wrote:

Hello, list!
I need to view the list of tables in a database. In MySQL I can do it with the command "SHOW TABLES". What about PostgreSQL?
Can I also see somehow the datatypes of tables' fields?
Konstantin

"man psql" will show you details of how to operate the psql application,
or when in it try "\?" and "\h" to get help. We also now support the
SQL-standard "information schema".

You'll also find the manuals have this information - available with your
installation and also online at http://www.postgresql.org/docs/

HTH
--
Richard Huxton
Archonet Ltd

#4Dick Davies
rasputnik@hellooperator.net
In reply to: Dick Davies (#2)
Re: How to view the list of tables?

* Dick Davies <rasputnik@hellooperator.net> [0241 10:41]:

* Konstantin Danilov <danilov_konst@list.ru> [0222 10:22]:

Hello, list!
I need to view the list of tables in a database. In MySQL I can do it with the command "SHOW TABLES". What about PostgreSQL?
Can I also see somehow the datatypes of tables' fields?

\dt in psjl lists tables

that should be 'psql', obviously..... :)

--
'Tempers are wearing thin. Let's hope some robot doesn't kill everybody.'
-- Bender
Rasputin :: Jack of All Trades - Master of Nuns

#5Shridhar Daithankar
ghodechhap@ghodechhap.net
In reply to: Konstantin Danilov (#1)
Re: How to view the list of tables?

On Tuesday 15 Feb 2005 3:46 pm, Konstantin Danilov wrote:

Hello, list!
I need to view the list of tables in a database. In MySQL I can do it with
the command "SHOW TABLES". What about PostgreSQL? Can I also see somehow
the datatypes of tables' fields?

In psql, you can try '\dt' and '\d table name'. Type \? for more commands..

Shridhar

#6Mihail Nasedkin
m.nasedkin.perm@mail.ru
In reply to: Konstantin Danilov (#1)
Re: How to view the list of tables?

Hello, Konstantin.

You wrote February, 15 2005 О©╫., 15:16:57:

KD> I need to view the list of tables in a database. In MySQL I
KD> can do it with the command "SHOW TABLES". What about PostgreSQL?

All tables:

select ...
from pg_catalog.pg_class
where c.relkind='r';

All tables of the public schema:

select ...
from pg_catalog.pg_class c join pg_catalog.pg_namespace n on c.relnamespace=n.oid
where c.relkind='r' and n.nspname='public';

KD> Can I also see somehow the datatypes of tables' fields?

select ...
from pg_catalog.pg_class c join pg_catalog.pg_attribute a on
c.oid=a.attrelid join pg_catalog.pg_type t on a.atttypid=t.oid

See also:

\d pg_class
\d pg_namespace
\d pg_attribute
\d pg_type

--
rgds,
Mihail mailto:m.nasedkin.perm@mail.ru