Re: SQL equivallent to "\ds" in psql - Mailing list pgsql-general

From Jason Earl
Subject Re: SQL equivallent to "\ds" in psql
Date
Msg-id 20011017220514.50889.qmail@web10002.mail.yahoo.com
Whole thread Raw
In response to SQL equivallent to "\ds" in psql  (Arcady Genkin <a.genkin@utoronto.ca>)
List pgsql-general
If you start psql with the -E flag it will output the
SQL queries it uses to do the nifty \ds command (and
all of the other \ commands).  This is a very handy
tool.

Here's what I get on my test system:

processdata=# \ds
********* QUERY *********
SELECT c.relname as "Name",
  (CASE WHEN relkind = 'S' THEN 'sequence'::text ELSE
'index'::text END) as "Type",
  u.usename as "Owner"
FROM pg_class c, pg_user u
WHERE c.relowner = u.usesysid AND relkind in ('S')
  AND c.relname !~ '^pg_'
UNION
SELECT c.relname as "Name",
  (CASE WHEN relkind = 'S' THEN 'sequence'::text ELSE
'index'::text END) as "Type",
  NULL as "Owner"
FROM pg_class c
WHERE not exists (select 1 from pg_user where usesysid
= c.relowner) AND relkind in ('S')
  AND c.relname !~ '^pg_'

ORDER BY "Name"
*************************

                List of relations
           Name            |   Type   |  Owner
---------------------------+----------+----------
 batterbatches_batchid_seq | sequence | earlj
 board_event_seq           | sequence | postgres
 field_event_seq           | sequence | postgres
 peeler_inst_seq           | sequence | postgres
 prod_journal_id_seq       | sequence | postgres
 raw_inst_seq              | sequence | postgres
 setting_inst_seq          | sequence | postgres
 setting_mods_seq          | sequence | postgres
 setting_specs_seq         | sequence | postgres
 train_event_seq           | sequence | postgres
 tscales_seq               | sequence | postgres
(11 rows)

Take care,
Jason

--- Arcady Genkin <a.genkin@utoronto.ca> wrote:
> Where does Postgres store information about the
> sequences?  I tried
> looking in the tables produced by "\dS", but could
> find no references
> to the sequences. :(
>
> What I want is an SQL equivallent of "\ds" command,
> which will return
> a list of all sequences in the current database.  I
> need this for a
> periodically run script so that I could keep an eye
> on all sequences
> in the database.
>
> Many thanks,
> --
> Arcady Genkin
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

pgsql-general by date:

Previous
From: Gaurav Priyolkar
Date:
Subject: Re: Dynamically created tables [WAS Re: "Relation x
Next
From: Bruce Momjian
Date:
Subject: Re: To Postgres Devs : Wouldn't changing the select limit