Re: Using bytea field...

From: rsmogura <rsmogura(at)softperience(dot)eu>
To: Sim Zacks <sim(at)compulab(dot)co(dot)il>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using bytea field...
Date: 2011-03-09 11:38:35
Message-ID: ead8b008a40e545977e58d2c051642d7@mail.softperience.eu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 09 Mar 2011 13:27:16 +0200, Sim Zacks wrote:
> MD5 is not collision resistant (using the immortal words of wikipedia
> http://en.wikipedia.org/wiki/MD5).
>
> This means that it is possible that multiple images will return the
> same md5 hash.
>
> The question is, if it screws up and says that an image already
> exists and then returns a different image when querying for it, how
> bad would that be.
>
>
> I've seen a lot of discussions in the past few years about how
> problematic the md5 approach is.
>
>
> Sim
>
>
> On 03/08/2011 09:06 PM, Andy Colson wrote:
>
>> On 3/8/2011 12:28 PM, Andre Lopes wrote:
>>> Hi,
>>>
>>> I'm using a bytea field to store small images in base64. I need to
>>> know if I can compare bytea rows for equality. To know for example
>>> if
>>> the file already exists in the database, this is possible with
>>> bytea?
>>>
>>> Best Regads,
>>>
>>
>> You dont need to use both base64 and bytea. You can store base64 in
>> text field... or just store the photo as-is into bytea.
>>
>> To answer your question: it would be faster if you computed an md5
>> (or sha or whatever) and stored it in the db, then you could check to
>> see if an image exists by searching for the md5, which would be way
>> faster, an send a lot less data over the wire.
>>
>> -Andy
>>

Every hash algorithm is not collision resistant, and in theory You need
to check equality of images. Hash function says that if hashes are
different, then images are different. It not says if hashes are same
then images are same.

Regards,
Radek

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Arturo Perez 2011-03-09 12:56:38 ER tool that supports domains and custom types?
Previous Message Sim Zacks 2011-03-09 11:32:44 Re: Using bytea field...