Re: Store base64 in database. Use bytea or text?

From: Andre Lopes <lopes80andre(at)gmail(dot)com>
To: Bill Moran <wmoran(at)potentialtech(dot)com>
Cc: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>, postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: Re: Store base64 in database. Use bytea or text?
Date: 2011-01-25 22:52:42
Message-ID: AANLkTikYTR2sxaPx5K-VkMokHoq4EkAupeHmSOnUutMC@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks for all the reply's.

I will be using PHP for now to insert data.

So I shouldn't use base64 to store images or any other kind of files.
I'm new to storing files in the database. This will be my first
experience.

I will research about PQescapeByteaConn.

Thanks for the help.

Best Regards,

On Tue, Jan 25, 2011 at 10:46 PM, Bill Moran <wmoran(at)potentialtech(dot)com> wrote:
> In response to Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>:
>
>> On 25 January 2011 22:27, Andre Lopes <lopes80andre(at)gmail(dot)com> wrote:
>> > Hi,
>> >
>> > I need to put some images on Base64 in a PostgreSQL database. Wich
>> > type should I use and what is the difference between using bytea or
>> > text to store Base64?
>>
>> I really don't think you want to do that. Base64 is used to make
>> binary data 7-bit safe for compatibility with legacy systems (i.e. to
>> embed arbitrary binary data within ASCII). Sometimes people escape
>> binary data as base64 to store it in their DB, but they typically
>> store it as bytea. Base64 probably isn't even a particularly good
>> choice for escaping binary, let alone storing it.
>>
>> You should just use a generic escaping function. libpq has
>> PQescapeByteaConn(), for example.
>
> A warning: last I checked, PHP's pg_escape_bytea() was broken, so be
> cautious if you're using PHP.
>
> --
> Bill Moran
> http://www.potentialtech.com
> http://people.collaborativefusion.com/~wmoran/
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dmitriy Igrishin 2011-01-25 22:58:39 Re: Store base64 in database. Use bytea or text?
Previous Message Dmitriy Igrishin 2011-01-25 22:49:25 Re: Store base64 in database. Use bytea or text?