Re: How to store text files in the postgresql?

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: 'PostgreSQL' <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to store text files in the postgresql?
Date: 2009-06-06 12:25:49
Message-ID: 4A2A604D.1080601@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

Browse pgsql-general by date

  From Date Subject
Next Message DimitryASuplatov 2009-06-06 13:37:20 Re: How to store text files in the postgresql?
Previous Message Leif B. Kristensen 2009-06-06 10:41:35 Re: How to store text files in the postgresql?