Re: How to store files into the DB with PHP. (bytea ?) - Mailing list pgsql-php

From tv@fuzzy.cz
Subject Re: How to store files into the DB with PHP. (bytea ?)
Date
Msg-id 5713.193.179.187.70.1233580658.squirrel@sq.gransy.com
Whole thread Raw
In response to Re: How to store files into the DB with PHP. (bytea ?)  (François Delpierre <pgsql@pivert.org>)
Responses Re: How to store files into the DB with PHP. (bytea ?)  (François Delpierre <pgsql@pivert.org>)
List pgsql-php
>> 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.




pgsql-php by date:

Previous
From: François Delpierre
Date:
Subject: Re: How to store files into the DB with PHP. (bytea ?)
Next
From: François Delpierre
Date:
Subject: Re: How to store files into the DB with PHP. (bytea ?)