Re: libpq: possible to get list of tables, fields, and types?

From: Tommi Mäkitalo <t(dot)maekitalo(at)epgmbh(dot)de>
To: john heasley <heas(at)shrubbery(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: libpq: possible to get list of tables, fields, and types?
Date: 2001-12-30 22:07:27
Message-ID: 3C2F901F.908@epgmbh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

john heasley wrote:

>using libpq, is it possible to get a list of tables (psql: \d equivalent),
>list of fields for each of those tables (psql: \d <table>), and types for
>each of the fields for a given container?
>
>there doesnt seem to be a way to do any of these, except for getting the
>field type of a returned tuple with PQftype() and looking up the returned
>oid in the pg_attribute.
>
>it does appear to be possible to query system tables (psql: \dS) for some
>of this data, such as pg_tables for a list of tables. yet there doesnt
>appear to be a way to associate these entries to a particular datbase
>container. am i missing some way to glue these tables together to get a
>list of tables per-container and fields per-table?
>
>tia,
>-heas
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>
Hi,

yes - system tables is the right answer.

pg_tables is a view on pg_class. And pg_class has the information you
need. Look into the developers guide for a description of systemtables.

Information about the attributes are in pg_attribute. Just join it with
pg_class:
select relname, attname, atttypid, attlen from pg_attribute join
pg_class on attrelid = pg_class.oid

A good source for information is pgaccess. It is a TCL-script. You can
find examples in the source.

Tommi

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Michel POURE 2001-12-31 07:48:02 Re: PostgreSQL GUI
Previous Message Dave Trombley 2001-12-30 19:43:07 Re: OIDs as object handles?