Re: \d functionality in a query. - Mailing list pgsql-general
From Joe Conway
Subject Re: \d functionality in a query.
Date
Msg-id 3DEC288A.3060001@joeconway.com
Whole thread Raw
In response to \d functionality in a query.  (Timothy Grant <tjg@craigelachie.org>)
Responses Re: \d functionality in a query.  (Timothy Grant <tjg@craigelachie.org>)
List pgsql-general
Timothy Grant wrote:
> Hi all,
>
> I'm sure it's a FAQ, and I discovered syscat.source, but was still not
> able to determine how to get a table description in a query.
>

Start psql with "-E" on the command line. Then you see all the internally
generated queries. This is using cvs, but it works in prior versions also:

$ psql -E regression
********* QUERY **********
BEGIN; SELECT usesuper FROM pg_catalog.pg_user WHERE usename = 'postgres'; COMMIT
**************************

Welcome to psql 7.4devel, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
        \h for help with SQL commands
        \? for help on internal slash commands
        \g or terminate with semicolon to execute query
        \q to quit

regression=# \d foo
********* 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 pg_catalog.pg_table_is_visible(c.oid)
       AND c.relname ~ '^foo$'
ORDER BY 2, 3;
**************************

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

********* QUERY **********
SELECT a.attname,
   pg_catalog.format_type(a.atttypid, a.atttypmod),
   a.attnotnull, a.atthasdef, a.attnum
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = '822242' AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
**************************

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

       Table "public.foo"
  Column |  Type   | Modifiers
--------+---------+-----------
  f1     | integer | not null
  f2     | text    | not null
  f3     | text[]  |
Indexes: foo_pkey primary key btree (f1, f2)


HTH,

Joe




pgsql-general by date:

Previous
From: Timothy Grant
Date:
Subject: \d functionality in a query.
Next
From: Timothy Grant
Date:
Subject: Re: \d
functionality in a query.