pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tv@fuzzy.cz
To: François Delpierre <pgsql@pivert.org>
Cc: pgsql-php@postgresql.org
Subject: Re: How to store files into the DB with PHP. (bytea ?)
Date: Mon, 2 Feb 2009 14:17:38 +0100 (CET)
Message-ID: <5713.193.179.187.70.1233580658.squirrel@sq.gransy.com> (raw)
In-Reply-To: <200902021355.35100.pgsql@pivert.org>
References: <200902021102.06157.pgsql@pivert.org>
	<38255.62.40.76.70.1233575704.squirrel@sq.gransy.com>
	<200902021355.35100.pgsql@pivert.org>

>> Choice between BYTEA and LOB is mostly about memory requirements - when
>> loading / storing BYTEA columns, you need enough memory to keep the
>> whole
>> object (data stored in the column). So when constructing the INSERT
>> statement you have to place the (escaped) data into it, and that may
>> exceed the memory_limit. With LOB objects this is not a problem thanks
>> to
>> streaming (you may open the LOB as a stream and read / write).
> So, there is no way to push binary directly into BYTEA without the need to
> escape ?

AFAIK no (at least in PHP) - you have to escape the data before using them
in SQL statement.

> I assume that you're talking about memory_limit parameter of PHP on the
> web
> server.
> Can we still use streaming through a stored procedure ?

The LOB principle is quite simple - each LOB is identified by OID, split
into multiple segments and stored in a table pg_largeobject. I am just
guessing but there are functions used to read / store the LOBs, so the
streaming might work (unless you want to use the tickets).

But I am just guessing - about a month ago I wrote an article about ways
to store files in a PostgreSQL database:

http://www.fuzzy.cz/en/articles/storing-files-in-a-postgresql-database/

The site is still under construction, so a lot of stuff is missing there
(sorry), but the last section might give you a hint how to mimic LOBs, get
rid of some of the BYTEA / LOB disadvantages.

>> Sorry, but you have some custom layer of stored procedures, so we may
>> only
>> guess. But LOBs are identified using an OID, so the procedures might
>> return OIDs.
> The web server user cannot read (or write) any table directly, so it's
> forced
> to use a stored procedure to read or write data. So, all the PHP fuctions
> on
> LOB are useless I guess.






view thread (7+ messages)  latest in thread

Message-ID: <5713.193.179.187.70.1233580658.squirrel@sq.gransy.com>
Permalink:  ../5713.193.179.187.70.1233580658.squirrel@sq.gransy.com/
Also on:    postgresql.org/message-id/5713.193.179.187.70.1233580658.squirrel@sq.gransy.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: tv@fuzzy.cz, pgsql@pivert.org
  Subject: Re: How to store files into the DB with PHP. (bytea ?)
  In-Reply-To: <5713.193.179.187.70.1233580658.squirrel@sq.gransy.com>
  References: <200902021102.06157.pgsql@pivert.org> <38255.62.40.76.70.1233575704.squirrel@sq.gransy.com> <200902021355.35100.pgsql@pivert.org> <5713.193.179.187.70.1233580658.squirrel@sq.gransy.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox