Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A3C646504AB for ; Tue, 9 Dec 2008 13:36:44 -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 32039-04 for ; Tue, 9 Dec 2008 13:36:39 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from rn-out-0910.google.com (rn-out-0910.google.com [64.233.170.186]) by mail.postgresql.org (Postfix) with ESMTP id 62D416504AC for ; Tue, 9 Dec 2008 13:36:37 -0400 (AST) Received: by rn-out-0910.google.com with SMTP id k40so71026rnd.0 for ; Tue, 09 Dec 2008 09:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=jvb2KyXWhsde0SEfaYa0sde7h/zQElys5dW7wa6Kv7o=; b=Twk4BZcGi3mdmWy9Y9gcu2IY2BZFmAOhH1NLMk9aR+BmcBIfffZwKJ6XCNCOdj3zXu W5BdcjVLoamdgXLgHWM/Mj6fwrbye+p1LCxEKSzRXxkzQ2A8Y/ahM5ymxHOpKhc1JtV6 WKJavc2rqz3k/RDQ9CdPkaF67rSO08MDHyzP0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=WcHvyLYFqiVfJs5fKtqA3NF7l9ZJp4xMJoN2RZicZxABbeKR3hnGB1bMv1wCV/I3mC 8QHjUlUNmuucTAIb/+mbI4xBrjdIr12Q0M1yppOJbw9SSGCM4Km9SPifO+5pfiVUfnS9 LXqLJU4LZY1XDIkbY6tp3/hvAtDuD1FDcnz8I= Received: by 10.151.156.1 with SMTP id i1mr405237ybo.34.1228844195531; Tue, 09 Dec 2008 09:36:35 -0800 (PST) Received: by 10.151.136.2 with HTTP; Tue, 9 Dec 2008 09:36:35 -0800 (PST) Message-ID: <8ec76080812090936g596abf91jdd8a184c3f56c32@mail.gmail.com> Date: Tue, 9 Dec 2008 12:36:35 -0500 From: "Whit Armstrong" To: "Jeroen Vermeulen" Subject: Re: simple example of copying data from a c/c++ array into postgres Cc: pgsql-interfaces@postgresql.org In-Reply-To: <493EA271.8010209@xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8ec76080812090708g93000f9l7e7f3e2162587331@mail.gmail.com> <493EA271.8010209@xs4all.nl> 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/11 X-Sequence-Number: 6828 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 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 >