pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: James Olin Oden <joden@lee.k12.nc.us>
To: Bob Smither <smither@C-C-I.Com>
Cc: Glenn Sullivan <glenn.sullivan@nmr.varian.com>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] Getting datatype before SELECT
Date: Wed, 30 Sep 1998 07:40:38 -0400
Message-ID: <81Sep29.063022edt.35713@gateway.lee.k12.nc.us> (raw)
References: <Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com>


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

In C he could do essentially the same thing.  One approach is to use system as
so:

   system("psql -d databasename -c \"\\d tablename\" -o /tmp/somefile");

And then he could open the file /tmp/somefile and parse his way through it.
Also, he can do the what perl does to create pipes (perl is written in C) and
essentially do the same thing as you are doing.  I personally would go with
the temp file, using my proccess id to as part of the tempfile name to make it
unique to my process, but it should not be to much work to make the proper
system calls to do the piping...james





view thread (11+ messages)  latest in thread

Message-ID: <81Sep29.063022edt.35713@gateway.lee.k12.nc.us>
Permalink:  ../81Sep29.063022edt.35713@gateway.lee.k12.nc.us/
Also on:    postgresql.org/message-id/81Sep29.063022edt.35713@gateway.lee.k12.nc.us

 · 

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: joden@lee.k12.nc.us, smither@C-C-I.Com, glenn.sullivan@nmr.varian.com, pgsql-sql@hub.org
  Subject: Re: [SQL] Getting datatype before SELECT
  In-Reply-To: <81Sep29.063022edt.35713@gateway.lee.k12.nc.us>
  References: <Pine.LNX.3.96.980929212156.20458A-100000@cci.c-c-i.com> <81Sep29.063022edt.35713@gateway.lee.k12.nc.us>

* 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