Re: Schema objects

From: Josh Trutwin <josh(at)trutwins(dot)homeip(dot)net>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Schema objects
Date: 2007-10-10 02:54:09
Message-ID: 20071009215409.575fc64b@prokofiev.trutwins.homeip.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Tue, 9 Oct 2007 17:04:35 -0300
"Lucas Martino" <lucas(dot)martino(at)gmail(dot)com> wrote:

> Hello,
> i need list all tables, functions, procedures, triggers,
> sequences of a specific schema. How can i do this?

I've always thought this syntax a little strange but:

\dt my_schema. (tables)
\df my_schema. (functions)

The period at the end is required.

For triggers there is no \ command (at least in 8.1) that I know of
so you can use a view I found somewhere - wish I could give proper
credit but can't remember where I found this.

I modified the original one to join in pg_namespace which allows you
to limit the view to show only triggers for a particular schema:

create view my_schema.showtriggers as
select trg.tgname as trigger_name, tbl.relname as table_name,
p.proname as function_name,
case trg.tgtype & cast(2 as int2)
when 0 then 'AFTER'
else 'BEFORE'
end as trigger_type,
case trg.tgtype & cast(28 as int2)
when 16 then 'UPDATE'
when 8 then 'DELETE'
when 4 then 'INSERT'
when 20 then 'INSERT, UPDATE'
when 28 then 'INSERT, UPDATE, DELETE'
when 24 then 'UPDATE, DELETE'
when 12 then 'INSERT, DELETE'
end as trigger_event
from pg_trigger trg, pg_class tbl, pg_proc p, pg_namespace nsp
where trg.tgrelid = tbl.oid
and trg.tgfoid = p.oid
and nsp.oid = tbl.relnamespace
and nsp.nspname = 'my_schema'
order by relname, trg.tgname;

Replace that line above "and nsp.nspname = 'my_schema'" to use your
schema name.

Josh

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message David Rovner 2007-10-10 13:29:42 Re: persistent 'psql: FATAL: "listen_addresses" cannot be changed after server start
Previous Message Steve Crawford 2007-10-09 22:08:02 Re: persistent 'psql: FATAL: "listen_addresses" cannot be changed after server start