Re: simple example of copying data from a c/c++ array into postgres - Mailing list pgsql-interfaces

From Whit Armstrong
Subject Re: simple example of copying data from a c/c++ array into postgres
Date
Msg-id 8ec76080812090936g596abf91jdd8a184c3f56c32@mail.gmail.com
Whole thread Raw
In response to Re: simple example of copying data from a c/c++ array into postgres  (Jeroen Vermeulen <jtv@xs4all.nl>)
Responses Re: simple example of copying data from a c/c++ array into postgres  (Jeroen Vermeulen <jtv@xs4all.nl>)
Re: [INTERFACES] simple example of copying data from a c/c++ array into postgres  (Jumshed <jumshed.akhtar@gmail.com>)
List pgsql-interfaces
Thanks, Jeroen,

I've used copy before from the prompt.  Thanks for alerting me to the
psql functions for it.

can copy be used to append data to a table?

The only reason I'm hesitant to use the copy command is because I
would have to render every row of my data to a string, and 64bit
doubles could mean long strings, formating issues, etc.

roughly what I was thinking was (this is pseudocode):

PGtuple myTuple = createTuple();
myTuple.push_back(toPGDate(myDate));
myTuple.push_back(toPGDouble(myDouble));
etc...

PGinsert_tuple(conn, myDestinationTable, myTuple);

are there facilities to do something like that, or am I really reaching here?

Thanks,
Whit



On Tue, Dec 9, 2008 at 11:53 AM, Jeroen Vermeulen <jtv@xs4all.nl> wrote:
> Whit Armstrong wrote:
>>
>> would someone mind showing me an example of making an insert from binary
>> data to postgres?
>
> Not an example, but have a look at the COPY command:
>
> http://www.postgresql.org/docs/8.3/interactive/sql-copy.html
>
> COPY FROM stdin lets you insert data in bulk, without having to issue a new
> INSERT for every row.  There are some handy libpq functions for feeding data
> into this mechanism:
>
> http://www.postgresql.org/docs/8.3/interactive/libpq-copy.html
>
> The "binary" part of what you're asking for is also possible, but probably
> doesn't buy you all that much.  Chances are you'd need to do some
> conversions anyway, and it introduces all sorts of maintenance risk for an
> optimization that's not likely to matter as much as disk flushes, network
> transfers etc.
>
>
> Jeroen
>


pgsql-interfaces by date:

Previous
From: "Haszlakiewicz, Eric"
Date:
Subject: Re: simple example of copying data from a c/c++ array into postgres
Next
From: Jeroen Vermeulen
Date:
Subject: Re: simple example of copying data from a c/c++ array into postgres