Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C1CB4B5DC10 for ; Thu, 26 May 2011 15:08:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 15617-05 for ; Thu, 26 May 2011 18:07:59 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from cooker.cnx.rice.edu (cooker.cnx.rice.edu [168.7.5.70]) by mail.postgresql.org (Postfix) with ESMTP id CD5B6B5DBF9 for ; Thu, 26 May 2011 15:07:59 -0300 (ADT) Received: from reedstrm by cooker.cnx.rice.edu with local (Exim 4.69) (envelope-from ) id 1QPeyS-0006jB-MI; Thu, 26 May 2011 13:07:56 -0500 Date: Thu, 26 May 2011 13:07:56 -0500 From: "Ross J. Reedstrom" To: Eric McKeeth Cc: emilu@encs.concordia.ca, pgsql-sql@postgresql.org Subject: Re: column type for pdf file Message-ID: <20110526180756.GC1938@rice.edu> References: <4DD42A1C.30202@encs.concordia.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/165 X-Sequence-Number: 35449 On Wed, May 18, 2011 at 05:06:36PM -0600, Eric McKeeth wrote: > On Wed, May 18, 2011 at 2:20 PM, Emi Lu wrote: > > > Hello, > > > > To save pdf files into postgresql8.3, what is the best column type? > > > > bytea, blob, etc? > > > > Thank you, > > Emi > > > > Everyone else has pointed out reasons for not doing this, and I agree with > them that in the large majority of cases just storing a reference to a file > stored outside the database is preferable. However, to answer the question > you asked, my rule of thumb is that if you need to store binary data in the > database is to use a bytea column, unless you need the random access > capabilities that the large object interface provides. A bytea column is > typically easier to use, and has proper transactional behavior, enforcement > of referential integrity, etc. > I'm with Eric on this one: for smaller use cases, the convenience of bytea in the db is nice. As to random access, I wrote a client-side wrapper for our middleware that implements a file iterator interface for python on top of substr(bytea,position,blocksize). I was sort of surprised at how well it performed. We're using it in production right now. I actually store files in a leaf table w/ and id and hash, with filenames in a separate linking table, so I'm even getting data deduplication (all the rage in biz these days) for free. Ross -- Ross Reedstrom, Ph.D. reedstrm@rice.edu Systems Engineer & Admin, Research Scientist phone: 713-348-6166 Connexions http://cnx.org fax: 713-348-3665 Rice University MS-375, Houston, TX 77005 GPG Key fingerprint = F023 82C8 9B0E 2CC6 0D8E F888 D3AE 810E 88F0 BEDE