agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
From: SRIRAMK@charlie.usd.edu
To: postgres@postgres.Berkeley.EDU
Cc: SRIRAMK@charlie.usd.edu
Subject: Clarification reg ASCII files to PG classes and back
Date: Sun, 10 Apr 1994 11:57:17 -0500 (CDT)
Message-ID: <940410115717.3196@charlie.usd.edu> (raw)

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.





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: SRIRAMK@charlie.usd.edu
  Subject: Re: Clarification reg ASCII files to PG classes and back
  In-Reply-To: <940410115717.3196@charlie.usd.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