Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[GENERAL] \d <Table> functionality in a query.

0 views
Skip to first unread message

Joe Conway

unread,
Dec 2, 2002, 11:16:01 PM12/2/02
to
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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majo...@postgresql.org)

Timothy Grant

unread,
Dec 3, 2002, 12:08:20 AM12/3/02
to
--=-YgJRvxZNNM+dtQVX2fQe
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

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.

I want my code to be able to get column names and column types.

Thanks.

--=20
Stand Fast,
tjg.

Timothy Grant
www.craigelachie.org

--=-YgJRvxZNNM+dtQVX2fQe
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQA97B5SI/KcrH1qjlsRAjv1AJ9o4ED/6owTmS1El7eZmMgX35JmVQCgkRck
DKZEHy/zQ8C5WMzMNyO9Q2I=
=hn3i
-----END PGP SIGNATURE-----

--=-YgJRvxZNNM+dtQVX2fQe--


0 new messages