pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bob Smither <smither@C-C-I.Com>
To: Glenn Sullivan <glenn.sullivan@nmr.varian.com>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Getting datatype before SELECT
Date: Tue, 29 Sep 1998 21:30:43 -0500 (CDT)
Message-ID: <Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com> (raw)
In-Reply-To: <3611135E.491D2598@nmr.varian.com>

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
======================================================================




view thread (11+ messages)  latest in thread

Message-ID: <Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com>
Permalink:  ../Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com/
Also on:    postgresql.org/message-id/Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: smither@C-C-I.Com, glenn.sullivan@nmr.varian.com, pgsql-sql@hub.org
  Subject: Re: [SQL] Getting datatype before SELECT
  In-Reply-To: <Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com>
  References: <3611135E.491D2598@nmr.varian.com> <Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com>

* 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