Re: [SQL] Getting datatype before SELECT - Mailing list pgsql-sql

From Bob Smither
Subject Re: [SQL] Getting datatype before SELECT
Date
Msg-id Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com
Whole thread Raw
In response to Getting datatype before SELECT  (Glenn Sullivan <glenn.sullivan@nmr.varian.com>)
List pgsql-sql
On Tue, 29 Sep 1998, Glenn Sullivan wrote:

:In my C code which communicates with the Postgres database,
:I have the need to determine the datatype of a column, before
:I have done a SELECT command.  I have the name of the column,
:but I cannot seem to figure out how to get the datatype information
:until after I have done a SELECT.  Then I can call  PQfnumber() and
:PQftype() to get the type.  Does anyone know how to do this?

Not at all sure how to do this from C, but from perl I do something like
this:

  $temp = `psql -d databasename -c "\\d tablename"`

The item between the `s is executed and the result returned to the
variable.  $temp now has the full structure of the table and can be parsed
to extract the column names and types.  The double \\ is needed to prevent
perl from thinking that \d is a meta character (I think).

The output of the command between the `s could also be redirected to a
file.

Hope this helps,
======================================================================
Bob Smither, Ph.D.      281-331-2744; fax:-4616      Smither@C-C-I.Com
Windows - making simple things easy, and interesting things impossible
======================================================================


pgsql-sql by date:

Previous
From: darcy@druid.net (D'Arcy J.M. Cain)
Date:
Subject: Re: [SQL] Getting datatype before SELECT
Next
From: James Olin Oden
Date:
Subject: Re: [SQL] Getting datatype before SELECT