Re: Data type for storing attached file

From: Bear Giles <bgiles(at)coyotesong(dot)com>
To: Ashish Tiwari <tashish786(at)gmail(dot)com>
Cc: "Ferrell, Denise D CTR NSWCDD, H11" <denise(dot)ferrell(dot)ctr(at)navy(dot)mil>, pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Data type for storing attached file
Date: 2017-07-11 18:01:40
Message-ID: CALBNtw5tzE1Wycc3z6w6_84oSAkE1zjNS=JoQAyQPW6mpkmnyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

If you want to get fancy you can create a "user defined type" for each type
of attachment. A very vanilla implementation would just make it a little
easier to figure out what you have but a RECORD type would allow you to
cache "interesting" information (e.g., the size of an image in pixels) and
a full implementation in C, java, etc., could compute that "interesting"
information from the raw data and even perform different types of
manipulation. E.g., you could have a "user defined function" that rescales
the image to a desired size.

The downsides are that few frameworks understand UDT. That's not a problem
if you're writing everything by hand or are able to use hand-written code
for specific functionality but could be a problem if you're trying to do
everything via a framework.

Another potential downside is if you don't host your own instance, e.g.,
you're using an AWS RDS instance. They won't allow you to use "C"
extensions. (You can still use pure SQL extensions.)

Finally if you want to be generic - you want "attachments" but don't want
to require explicit types, you can either use a generic UDT or create a
polymorphic one where the DB sees the UDT but you have UDF that allow you
to cast the type to a specific format if possible.

On Tue, Jul 11, 2017 at 9:31 AM, Ashish Tiwari <tashish786(at)gmail(dot)com> wrote:

> Hi Ferrell ,
>
> I have encoded the files in base64 and stored binary data in text.this can
> be stored in bytea too.
>
> Thanks.
>
> On Jul 11, 2017 8:41 PM, "Ferrell, Denise D CTR NSWCDD, H11" <
> denise(dot)ferrell(dot)ctr(at)navy(dot)mil> wrote:
>
>> Using PostgreSQL v9.3 on Linux...
>>
>> What data type would be used to store an attachment (file, could be .txt,
>> .doc, .xls, etc.) into a column?
>>
>> Thank you in advance,
>> Denise
>>
>>
>> --
>> Sent via pgsql-admin mailing list (pgsql-admin(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-admin
>>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message ghiureai 2017-07-11 18:07:27 autovacuum logs question
Previous Message Ashish Tiwari 2017-07-11 15:31:02 Re: Data type for storing attached file