Re: sql syntax to replace desc - Mailing list pgsql-general

From Richard Broersma
Subject Re: sql syntax to replace desc
Date
Msg-id 396486430901301834s167296dei7f91732338e63fea@mail.gmail.com
Whole thread Raw
In response to sql syntax to replace desc  (hendra kusuma <penguinroad@gmail.com>)
List pgsql-general
On Fri, Jan 30, 2009 at 6:20 PM, hendra kusuma <penguinroad@gmail.com> wrote:

> I'm not talking about \d option at psql console since I need that data
> to be called from programming language such as PHP and Ruby

Here is a way to see what \d is doing:

richard@dell-desktop:~$ psql -E -U richard

richard=> \d animals
********* QUERY **********
SELECT c.oid,
  n.nspname,
  c.relname
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ '^(animals)$'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
**************************

********* QUERY **********
SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules,
relhasoids , reltablespace
FROM pg_catalog.pg_class WHERE oid = '16525'
**************************

********* QUERY **********
SELECT a.attname,
  pg_catalog.format_type(a.atttypid, a.atttypmod),
  (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
   FROM pg_catalog.pg_attrdef d
   WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
  a.attnotnull, a.attnum
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = '16525' AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
**************************

********* QUERY **********
SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered,
i.indisvalid, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
c2.reltablespace
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
WHERE c.oid = '16525' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname
**************************

********* QUERY **********
SELECT r.conname, pg_catalog.pg_get_constraintdef(r.oid, true)
FROM pg_catalog.pg_constraint r
WHERE r.conrelid = '16525' AND r.contype = 'c' ORDER BY 1
**************************

********* QUERY **********
SELECT c.oid::regclass FROM pg_catalog.pg_class c,
pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid =
'16525' ORDER BY inhseqno ASC
**************************

             Table "public.animals"
   Column   |         Type          | Modifiers
------------+-----------------------+-----------
 animalname | character varying(20) | not null
 animaltype | character varying(20) | not null
 weight     | numeric(6,2)          |
Indexes:
    "animals_pkey" PRIMARY KEY, btree (animalname, animaltype)
    "animals_animalname_key" UNIQUE, btree (animalname)
Check constraints:
    "animals_animaltype_check" CHECK (animaltype::text = ANY
(ARRAY['BEAR'::character varying, 'WOLF'::character varying,
'COUGAR'::character varying, 'SHEEP'::character varying,
'DEER'::character varying]::text[]))

richard=>


--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

pgsql-general by date:

Previous
From: hendra kusuma
Date:
Subject: sql syntax to replace desc
Next
From: Martin Gainty
Date:
Subject: Re: sql syntax to replace desc