Thread: Newbie question about blobs and bytea

Newbie question about blobs and bytea

From
Mary Anderson
Date:
Hi all,

    I have read the stuff on blobs and bytea columns many time in the
past few years , but just do not get it.  I have short files, stored on
the operating system as - say - pdf files.  Can I store the content of
one of these files in a bytea column?  If I do, how do I store and
retrieve the file for display on the screen?  If I do this in a bytea
column do I need to escape anything?


Thanks,

Mary Anderson

Re: Newbie question about blobs and bytea

From
Ognjen Blagojevic
Date:
Mary Anderson wrote:
>    I have read the stuff on blobs and bytea columns many time in the
> past few years , but just do not get it.  I have short files, stored on
> the operating system as - say - pdf files.  Can I store the content of
> one of these files in a bytea column?  If I do, how do I store and
> retrieve the file for display on the screen?  If I do this in a bytea
> column do I need to escape anything?

1. You may store your files in the bytea columns.
2. Retrieval depends on several things: what front end you use for
retrieval, and how do you intend to display files. For instance, if you
are using JDBC driver, you may read the files into the Java byte[]
variable using regular SELECT statement. If you plan to display your PDF
files inside a web application, you may then use a servlet, to create
HTTP response to the user. The user agent will interpret the response
and open a PDF file.
3. Again, escaping depends on your front end. Most probably the driver
will do the escaping for you, you will just read and write arrays of
bytes, similar to reading and writing files on the file system.

Regards,
Ognjen