>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().
pgsql-interfaces by date
|Next:||From: Cary B. O'Brien||Date: 1998-11-11 01:34:47|
|Subject: Re: [INTERFACES] how to obtain column info|
|Previous:||From: Ken J. Wright||Date: 1998-11-11 00:38:02|
|Subject: how to obtain column info|