Re: SQL Command - To List Tables ?

From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: Robby Russell <rrussell(at)commandprompt(dot)com>
Cc: "\"PostgreSQL [GENERAL] \" List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL Command - To List Tables ?
Date: 2003-08-27 13:22:04
Message-ID: 733C4214-D891-11D7-A0EA-000393C78AC0@visualdistortion.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Wednesday, August 27, 2003, at 07:57 AM, Robby Russell wrote:

> Peter Moscatt wrote:
>
>> Is there a SQL command I can issue which will list all the TABLES
>> within
>> a database ?
>>
>> Pete
>>
>
> Well, when you are the postgres commandline client, you can type
> # \dt
>
> That will show all the tables in your current database.
>

If you would actually like to issue a command, you can start psql with
the -E option. So it will show you all the queries it uses:
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i'
THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as
"Type",
u.usename as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;

Which of course you can pare down to get just the information you want.

Jeff

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeffrey Melloy 2003-08-27 13:22:58 Re: Weird psql problem
Previous Message Doug McNaught 2003-08-27 13:21:34 Re: Postgresql for Solaris on Sparc