question about libpq - Mailing list pgsql-novice

From Jay Campbell
Subject question about libpq
Date
Msg-id 3442EA66-81D4-11D8-B35C-000A9599CF8E@mac.com
Whole thread Raw
Responses Re: question about libpq
List pgsql-novice
Hello all.  I am trying to use libpq to store some large blocks of text
in a postgresql table, and I can't figure out how to make it behave
like I want.  Any advice would be very welcome.

I have a large block of text coming in on STDIN, and I would like to
dump it all to a given field.  In a perfect world, I could just do
this:

PQmagicFunction(conn, my_row_oid, my_field_number, STDIN);

...and it would grab the data from STDIN and append it to the given
field in the given row, until EOF.  Now, since PQmagicFunction doesn't
exist (as far as I know), I could buffer it and do the following:

char buffer[1024];
PQaddFromCharacterBufferToField(conn, my_row_oid, my_field_number,
buffer, 1024);

but again, I haven't seen PQaddFromCharacterBufferToField(PGconn *,
Oid, int, char *, int) in any of the header files.  :)

...as it stands, i'm having to escape the buffer contents and do a
PQexec 'update' command that appends the 1024 escaped characters to the
field, every time the buffer fills.  (which could be thousands of times
as the filesize could be in the megabytes)  Perhaps I'm doing it right,
but it sure feels icky.  I keep getting this feeling that there is a
better way (or two).

can someone point me in the right direction please?  If my explanation
didn't make sense, please tell me that too.

Thanks in advance,
-jay


pgsql-novice by date:

Previous
From: Josh Berkus
Date:
Subject: Re: dynamic interval in plpgsql
Next
From: Joe Conway
Date:
Subject: Re: question about libpq