Skip site navigation (1) Skip section navigation (2)

Re: sql syntax to replace desc

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: hendra kusuma <penguinroad(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sql syntax to replace desc
Date: 2009-01-31 02:34:40
Message-ID: 396486430901301834s167296dei7f91732338e63fea@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
On Fri, Jan 30, 2009 at 6:20 PM, hendra kusuma <penguinroad(at)gmail(dot)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(at)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

In response to

pgsql-general by date

Next:From: Martin GaintyDate: 2009-01-31 02:38:46
Subject: Re: sql syntax to replace desc
Previous:From: hendra kusumaDate: 2009-01-31 02:20:27
Subject: sql syntax to replace desc

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group