agora inbox for postgres@postgres.berkeley.edu
help / color / mirror / Atom feedFrom: Paul M. Aoki <aoki@postgres.Berkeley.EDU>
To: SRIRAMK@charlie.usd.edu
Cc: postgres@postgres.Berkeley.EDU
Subject: Re: Clarification reg ASCII files to PG classes and back
Date: Sun, 10 Apr 94 14:06:02 -0700
Message-ID: <199404102106.OAA14296@faerie.CS.Berkeley.EDU> (raw)
In-Reply-To: <940410115717.3196@charlie.usd.edu>
SRIRAMK@charlie.usd.edu writes:
> PQsetdb ("ftransferdb1");
> PQexec ("begin");
> PQexec ("copy LINE from "/home/coyote/postgres/sriramk/srcfile"");
this last line isn't correct C, but i assume you know that..
> 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.
what someone was trying to say with the following (rather opaque)
statement in the reference manual:
The copy command in POSTGRES has options to read from or write to the net-
work connection used by LIBPQ. Therefore, functions are necessary to
access this network connection directly so applications may take full
advantage of this capability.
is that PQgetline, PQputline and PQendcopy are for use with copy
to/from stdin/stdout. what isn't very clear is that they are ONLY
for use with copy to/from stdin/stdout.
if you're happy with copying from a particular file, you don't
need PQputline and PQendcopy. i just ran the following program
and it works:
main()
{
PQsetdb("foo");
PQexec("create foo (a=int4)");
PQexec("copy foo from \"/home2/aoki/xxx\"");
}
although it doesn't do any error-checking, etc.
most people want to be able to generate instances from within
their program and send them directly to the backend (without
an intermediate file), which is what the PQputline stuff is for.
> I had earlier addressed Postgres and tried out the alternative 1 in line
> with suggestion from Mr Aoki
hey, i didn't suggest *that*. don't be puttin' words in my
mouth.. :-) i suggested you take a look at the example in
the libpq section and at the source for monitor.
the reason i said to look at monitor is that there are some
real-world considerations with respect to error-checking,
buffer-handling, etc. that you won't see in a tiny sample
program.
--
Paul M. Aoki | CS Div., Dept. of EECS, UCB | aoki@postgres.Berkeley.EDU
| Berkeley, CA 94720 | ...!uunet!ucbvax!aoki
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: aoki@postgres.Berkeley.EDU, SRIRAMK@charlie.usd.edu
Subject: Re: Clarification reg ASCII files to PG classes and back
In-Reply-To: <199404102106.OAA14296@faerie.CS.Berkeley.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