agora inbox for postgres@postgres.berkeley.edu
help / color / mirror / Atom feedFrom: Tom Cox <coxt@tahoma.cwu.edu>
To: SRIRAMK@charlie.usd.edu
Cc: postgres@postgres.Berkeley.EDU
Cc: SRIRAMK@charlie.usd.edu
Subject: Re: Clarification reg ASCII files to PG classes and back
Date: Sun, 10 Apr 1994 23:16:38 -0700 (PDT)
Message-ID: <Pine.3.89.9404102325.A15294-0100000@tahoma.cwu.edu> (raw)
In-Reply-To: <940410115717.3196@charlie.usd.edu>
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
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 using the --to and --cc options:
reply via email
To: postgres@postgres.berkeley.edu
Cc: coxt@tahoma.cwu.edu, SRIRAMK@charlie.usd.edu
Subject: Re: Clarification reg ASCII files to PG classes and back
In-Reply-To: <Pine.3.89.9404102325.A15294-0100000@tahoma.cwu.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox