Re: md5() sorting - Mailing list pgsql-general

From Lew
Subject Re: md5() sorting
Date
Msg-id 4oSdncY2-KHOMqXanZ2dnUVZ_ufinZ2d@comcast.com
Whole thread Raw
In response to Re: md5() sorting  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: md5() sorting  ("Scott Marlowe" <scott.marlowe@gmail.com>)
List pgsql-general
Karsten Hilbert wrote:
> On Wed, Nov 07, 2007 at 05:36:47PM +0200, Marko Kreen wrote:
>
>>>> I'm wondering if you cast the md5sum as a bytea instead of text and
>>>> then sort, if that would solve it simply.
>>> Along the lines of
>>>
>>>         ... ORDER BY decode(md5('...'), 'hex');
>>>
>> Maybe using digest(.., 'md5') function from pgcrypto would be better?
>> It gives bytea immidiately.
>
> Sounds better at first, yes, but requires pgcrypto to be
> installed on machines onto which GNUmed is to be deployed.
>
> Thanks for the suggestion, though.

Since an MD5 hash is a byte array, using text (or any locale-encoded
representation) of it is a mistake.  Hashes are not strings and shouldn't be
treated as such.

--
Lew

pgsql-general by date:

Previous
From: "froast"
Date:
Subject: how should I do to disable the foreign key in postgres?
Next
From: Lew
Date:
Subject: Re: update record with two-column primary key