Re: How to store text files in the postgresql? - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: How to store text files in the postgresql?
Date
Msg-id 4A2A604D.1080601@iol.ie
Whole thread Raw
In response to How to store text files in the postgresql?  (DimitryASuplatov <genesup@gmail.com>)
List pgsql-general
On 06/06/2009 11:41, DimitryASuplatov wrote:

> My task is to store a lot (10^5) of small ( <10 MB) text files in the
> database with the ability to restore them back to the hard drive on
> demand.
>
> That means that I need two functions. First - grab file from the
> directory, store it in the database and delete from the disk; second -
> recreate in back to the disk.
>
>
> 1/ Is it possible?

Yes. You can do this in your favourite scripting language - PHP, Perl,
etc etc.

> 2/ Could you give me some quick tips on how to manage it from the start
> so that I knew what to look for in the manual?

You haven't given much detail on your needs, but something like this
should do you:

create table the_files (
  file_id serial,
  file_data text,
  ...[any other metatdata you need]...
  constraint files_pk primary key (file_id)
);

The "serial" type is a pseudo-type which creates a sequence, which in
turn supplies incrementing integers, while "text" allows you to store
strings of arbitrary length. - Look them up in the docs under "Data types".

Really, though, I think your question is more about how to write the
script which reads the files from the filesystem and restores them there
- this depends on what language you use.

Ray.


------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------


pgsql-general by date:

Previous
From: "Leif B. Kristensen"
Date:
Subject: Re: How to store text files in the postgresql?
Next
From: Bill Moseley
Date:
Subject: Select last week