Re: \d <Table> functionality in a query.

From: Timothy Grant <tjg(at)craigelachie(dot)org>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: \d <Table> functionality in a query.
Date: 2002-12-03 03:52:21
Message-ID: 1038887541.6030.11.camel@reepicheep.craigelachie.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joe,

Thank you so very much! That is gonna be hugely helpful!

Wow! Slightly more involved queries than I expected! Anyway that's a
huge help.

On Mon, 2002-12-02 at 19:44, Joe Conway wrote:
> 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
>
>
>
>
--
Stand Fast,
tjg.

Timothy Grant
www.craigelachie.org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2002-12-03 04:00:45 Re: Please help on MS SQL Procedure (@@rowcount) translate
Previous Message Joe Conway 2002-12-03 03:44:10 Re: \d <Table> functionality in a query.