Re: listing relations

From: Greg Smith <gsmith(at)gregsmith(dot)com>
To: Brandon Metcalf <brandon(at)geronimoalloys(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: listing relations
Date: 2009-06-11 22:12:06
Message-ID: alpine.GSO.2.01.0906111749460.26947@westnet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 11 Jun 2009, Brandon Metcalf wrote:

> Is there a "\" command to show all tables in the current search path?

SELECT
nspname,relname,relkind
FROM
pg_class c,
pg_namespace n
WHERE
c.relnamespace = n.oid AND
relkind='r' AND
nspname !~ '^pg_toast' AND
nspname = ANY(current_schemas(false))
ORDER BY
nspname,relname;

Change "false" to "true" if you want to include the stuff in pg_catalog
too. Remove the filter on relkind if you want to see things besides just
tables. There's a bunch of other system info functions you might find
useful documented at
http://www.postgresql.org/docs/8.3/static/functions-info.html as well.

(The pg_toast filter is probably redundant here, I try to keep that in all
these pg_class/pg_namespace join examples because it's handy for more
normal queries)

--
* Greg Smith gsmith(at)gregsmith(dot)com http://www.gregsmith.com Baltimore, MD

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Leif B. Kristensen 2009-06-11 22:31:12 Re: When to use cascading deletes?
Previous Message Alvaro Herrera 2009-06-11 22:10:04 Re: Postgres auditing features