X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 74A08D1DB17 for ; Tue, 9 Mar 2004 21:03:07 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 57400-05 for ; Tue, 9 Mar 2004 17:03:06 -0400 (AST) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 5F596D1DAFB for ; Tue, 9 Mar 2004 17:03:04 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.35 #1) id 1B0oNS-0003iS-0Z; Tue, 09 Mar 2004 21:03:05 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 27C7017884; Tue, 9 Mar 2004 21:02:52 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 9685F16C1B; Tue, 9 Mar 2004 21:02:48 +0000 (GMT) From: Richard Huxton To: "Frost, Mr. Michael (contractor)" Subject: Re: bytea or blobs? Date: Tue, 9 Mar 2004 21:02:46 +0000 User-Agent: KMail/1.5 References: <99B7BBD611EEC047B926ECF189E737787C70AE@zeus.w2k.nrlmry.navy.mil> In-Reply-To: <99B7BBD611EEC047B926ECF189E737787C70AE@zeus.w2k.nrlmry.navy.mil> Cc: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200403092102.46987.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/91 X-Sequence-Number: 17190 On Tuesday 09 March 2004 18:33, you wrote: > Hi. If it wouldn't be too much of a bother could you send me sample code > that used SQL commands to insert a bytea as well as retrieve, that includes > the encode / decode stuff? I have been struggling to figure out how to get > this to work. I am using SQL embedded in C. Michael, I'm cc-ing this to the sql list since I don't use embedded SQL myself. > For instance if I have data stored in something called (char *pData), how > would I put that into a bytea field and then retrieve it? > > Say, the table was something like: > create table testit ( id integer, thedata bytea, primary key ( id ) ); > > Then, inside the C with embedded SQL code: > > char *pData; > -- Read something into pData.. > exec sql insert into testit ( id, thedata ) values ( 10, :pData ); Well, AFAIK the main thing to remember with bytea is that it can contain characters that need escaping (in particular ascii 0). What worries me about the above is that there is no obvious way for pData to contain a \0. Now, the encode/decode functions work simply enough and using the 'escape' encoding will convert back/fore quite neatly. Alternatively, you might prefer 'base64' - on average a less compact format I'd guess. I don't know whether the ECPG interface lets you pass "raw" binary back and fore or not, but hopefully someone else will. -- Richard Huxton Archonet Ltd