pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryan White <brywhite@visi.net>
To: pgsql-interfaces@postgreSQL.org
To: Ken J. Wright <ken@ori-ind.com>
Subject: Re: [INTERFACES] how to obtain column info
Date: Tue, 10 Nov 1998 20:28:15 -0500
Message-ID: <000401be0d12$8ee690c0$8bc708d1@bryans400> (raw)

>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().




view thread (5+ messages)  latest in thread

Message-ID: <000401be0d12$8ee690c0$8bc708d1@bryans400>
Permalink:  ../000401be0d12$8ee690c0$8bc708d1@bryans400/
Also on:    postgresql.org/message-id/000401be0d12$8ee690c0$8bc708d1@bryans400

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: brywhite@visi.net, ken@ori-ind.com
  Subject: Re: [INTERFACES] how to obtain column info
  In-Reply-To: <000401be0d12$8ee690c0$8bc708d1@bryans400>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox