Skip site navigation (1) Skip section navigation (2)

question about libpq

From: Jay Campbell <fork42(at)mac(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: question about libpq
Date: 2004-03-29 22:55:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: 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 

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.  :) 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,


pgsql-novice by date

Next:From: Joe ConwayDate: 2004-03-29 23:06:59
Subject: Re: question about libpq
Previous:From: Josh BerkusDate: 2004-03-29 21:46:05
Subject: Re: dynamic interval in plpgsql

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group