pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryan White <bryan@arcamax.com>
To: 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 09:19:40 -0400
Message-ID: <001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.com> (raw)

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



Is that not what popen/pclose are for.  i.e
    FILE *f = popen("psql -d databasename -c \"\\d tablename\"","r");
    ...
    pclose(f);





view thread (11+ messages)  latest in thread

Message-ID: <001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.com>
Permalink:  ../001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.com/
Also on:    postgresql.org/message-id/001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.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: bryan@arcamax.com, 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: <001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.com>
  References: <001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.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