Re: [INTERFACES] how to obtain column info

From: "Bryan White" <brywhite(at)visi(dot)net>
To: <pgsql-interfaces(at)postgreSQL(dot)org>, "Ken J(dot) Wright" <ken(at)ori-ind(dot)com>
Subject: Re: [INTERFACES] how to obtain column info
Date: 1998-11-11 01:28:15
Message-ID: 000401be0d12$8ee690c0$8bc708d1@bryans400
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

>With libpq, how do you obtain column info (like type) for a table *before*
>returning a result set? For instance, knowing the column type before
>constructing an insert statement. A date will need quotes, a number won't,
>a string will, etc.

I just had to figure this one out myself.

First do a select of the form: select * from table where 'false'::bool;

Then call PQftype to get the type OID for fields.

Now comes the part that was not well documented and somebody tell me if
there is a better way. On my machine the pgsql source is in /usr/src/pgsql
and the install files are in /usr/local/pgsql. The file
/usr/src/pgsql/src/include/catalog/pg_type.h contains #defines for the type
oid values. Unfortunatly it also contains lots of other stuff that the 'c'
compiler might not like. Actually with the right macros you could probably
use it as it. Note this file is not in /usr/local/pgsql/catalog where you
might expect it.

What I did was copy the file to another directory and strip out all the
funky stuff. What you want are the lines of the form:

#define XXXXOID NN

where XXXX is a type and NN is a number. Compare these values against the
return of PQftype().

Browse pgsql-interfaces by date

  From Date Subject
Next Message Cary B. O'Brien 1998-11-11 01:34:47 Re: [INTERFACES] how to obtain column info
Previous Message Ken J. Wright 1998-11-11 00:38:02 how to obtain column info