Re: SQL equivallent to "\ds" in psql

From: Jason Earl <jdearl(at)yahoo(dot)com>
To: Arcady Genkin <a(dot)genkin(at)utoronto(dot)ca>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL equivallent to "\ds" in psql
Date: 2001-10-17 22:05:14
Message-ID: 20011017220514.50889.qmail@web10002.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)genkin(at)utoronto(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2001-10-17 22:34:34 Re: To Postgres Devs : Wouldn't changing the select limit
Previous Message Gaurav Priyolkar 2001-10-17 21:47:50 Re: Dynamically created tables [WAS Re: "Relation x