Re: getting attribute names, types

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Surabhi Ahuja <surabhi(dot)ahuja(at)iiitb(dot)ac(dot)in>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: getting attribute names, types
Date: 2005-03-07 03:50:56
Message-ID: 20050307035056.GA23219@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 03, 2005 at 03:01:10PM +0530, Surabhi Ahuja wrote:

> i have to write a program in C++ using libpq. The program
> establishes a connection with the desired database.
> I have 4 tables in the database. Now i want to get the list of
> attribute names, their data types for each of those 4 tables. how
> do i do that?

You could query the system catalogs or the Information Schema (the
latter available in 7.4 and later). Another way would be to query
the tables themselves and use the functions described under "Retrieving
Query Result Information" in the libpq documentation.

http://www.postgresql.org/docs/8.0/interactive/catalogs.html
http://www.postgresql.org/docs/8.0/interactive/information-schema.html
http://www.postgresql.org/docs/8.0/interactive/libpq-exec.html#LIBPQ-EXEC-SELECT-INFO

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-03-07 04:30:57 Re: Pg 8.01 big trouble with LIMIT (bug !?)
Previous Message Greg Sabino Mullane 2005-03-07 01:04:20 Re: Error: "catalog is missing 8 attribute(s) for relid 16683"