Re: [SQL] Getting datatype before SELECT

From: Bob Smither <smither(at)C-C-I(dot)Com>
To: Glenn Sullivan <glenn(dot)sullivan(at)nmr(dot)varian(dot)com>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: [SQL] Getting datatype before SELECT
Date: 1998-09-30 02:30:43
Message-ID: Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)C-C-I(dot)Com
Windows - making simple things easy, and interesting things impossible
======================================================================

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message James Olin Oden 1998-09-30 11:40:38 Re: [SQL] Getting datatype before SELECT
Previous Message D'Arcy J.M. Cain 1998-09-30 02:10:44 Re: [SQL] Getting datatype before SELECT