Return-Path: owner-postman 
Delivery-Date: Mon, 11 Apr 94 05:33:05 -0700
Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id XAA17691 for postgres-redist; Sun, 10 Apr 1994 23:16:54 -0700
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199404110616.XAA17691@nobozo.CS.Berkeley.EDU>
X-Authentication-Warning: nobozo.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from aurora.cwu.edu (aurora.cwu.edu [198.104.65.9]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id XAA17682 for <postgres@nobozo.CS.Berkeley.EDU>; Sun, 10 Apr 1994 23:16:50 -0700
Received: from tahoma.cwu.edu by AURORA.CWU.EDU (PMDF V4.2-11 #5569) id
 <01HB1016A66O000AC2@AURORA.CWU.EDU>; Sun, 10 Apr 1994 23:16:42 PDT
Received: from localhost (coxt@localhost) by tahoma.cwu.edu (8.6.5/8.6.5) id
 XAA15411; Sun, 10 Apr 1994 23:16:38 -0700
Date: Sun, 10 Apr 1994 23:16:38 -0700 (PDT)
From: Tom Cox <coxt@tahoma.cwu.edu>
Subject: Re: Clarification reg ASCII files to PG classes and back
In-reply-to: <940410115717.3196@charlie.usd.edu>
To: SRIRAMK@charlie.usd.edu
Cc: postgres@postgres.Berkeley.EDU, SRIRAMK@charlie.usd.edu
Message-id: <Pine.3.89.9404102325.A15294-0100000@tahoma.cwu.edu>
MIME-version: 1.0
Content-type: TEXT/PLAIN; charset=US-ASCII
Content-transfer-encoding: 7BIT
Resent-To: postgres-redist@postgres.Berkeley.EDU
Resent-Date: Sun, 10 Apr 94 23:16:54 -0700
Resent-XMts: smtp



On Sun, 10 Apr 1994 SRIRAMK@charlie.usd.edu wrote:

> I am writing an application in C which will has to post data from an ASCII
> file to Postgres classes. I have tried using the copy command
> embedded in C program as follows in approach 1:
> 
> Approach 1.
> 
> #include <stdio.h>
> #include "/home/coyote/postgres/src/backend/tmp/libpq.h"
> 
> main()
> {
> 	PortalBuffer *p;
> 	int i, n;
> 	PQsetdb ("ftransferdb1");
> 	PQexec ("begin");
> 	PQexec ("copy LINE from "/home/coyote/postgres/sriramk/srcfile""); 
>         PQputline(".\n");
>         PQendcopy();
> 	PQexec ("end");
> }
> 
> Each individual line in the srcfile needs to be copied as  an individual
> tuple in the class called LINE. It worked fine when I used the copy command
> at the Postgres prompt. But it didn't work in a C program as above.
> 
> So alternatively I tried out the following approach 2 which worked.
> 
> Approach 2
> 
> #include <stdio.h>
> 
> main()
> {
> 	
>      system ("monitor ftransferdb1 < tranferfile");
> }
> 
> where transferfile is  the following:
>                          
>      copy LINE from "/home/coyote/postgres/sriramk/srcfile" \g
> 
> I feel Approach 1 is a better way of doing it (if it can be made to work)
> rather than creating a number of command files (like transferfile above)
> 
> I had earlier addressed Postgres and tried out the alternative 1 in line
> with suggestion from Mr Aoki, but I must be missing some point which
> prevents the approach 1 from working.
> 
> A suitable and good solution is required as my project involves transferring
> large volumes of data to and fro.
> 
> Looking forward to suggestions,
> 
> Thanks
> Sriram Kal.
> 

A approach that I used when transfering ASCII information to a pg 
database looks something like this.

void main(void)
{
  FILE *pp, *source;
  pp = popen("monitor grass", "w");
  source = fopen(/*source filename*/,"r");
  /*  fscanf(source) and fprintf(pp, "append class(field = %s) \g\q", 
  somestring) statements go here. */
  pclose(pp);
   
}

This approach worked the first time with no problems.  I redirected the
program output to a log file that I could later look at to verify every was
correctly copied.

-Tom Cox
coxt@cwu.edu


