Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CCE9D64FECD for ; Thu, 11 Dec 2008 12:23:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 21828-03 for ; Thu, 11 Dec 2008 12:23:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp-vbr7.xs4all.nl (smtp-vbr7.xs4all.nl [194.109.24.27]) by mail.postgresql.org (Postfix) with ESMTP id 01FEC64FC25 for ; Thu, 11 Dec 2008 12:23:15 -0400 (AST) Received: from [10.0.0.142] (ppp-124-120-188-99.revip2.asianet.co.th [124.120.188.99]) (authenticated bits=0) by smtp-vbr7.xs4all.nl (8.13.8/8.13.8) with ESMTP id mBBGLAP3069374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 11 Dec 2008 17:21:14 +0100 (CET) (envelope-from jtv@xs4all.nl) Message-ID: <49413DE7.8040703@xs4all.nl> Date: Thu, 11 Dec 2008 23:20:55 +0700 From: Jeroen Vermeulen User-Agent: Thunderbird 2.0.0.18 (X11/20081125) MIME-Version: 1.0 To: Whit Armstrong CC: pgsql-interfaces@postgresql.org Subject: Re: simple example of copying data from a c/c++ array into postgres References: <8ec76080812090708g93000f9l7e7f3e2162587331@mail.gmail.com> <493EA271.8010209@xs4all.nl> <8ec76080812090936g596abf91jdd8a184c3f56c32@mail.gmail.com> In-Reply-To: <8ec76080812090936g596abf91jdd8a184c3f56c32@mail.gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/12 X-Sequence-Number: 6829 Whit Armstrong wrote: > can copy be used to append data to a table? Yes. The only thing it will not do for you is update existing rows. > 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? In libpqxx I mostly provide self-made text conversions, but you can also use the standard library to "print" most values into text buffers. Just be sure to use the C locale where you do this, or you might end up with strange bugs depending on local notations! Jeroen