Re: Constraint: string length must be 32 chars

Поиск
Список
Период
Сортировка
От Rob Sargent
Тема Re: Constraint: string length must be 32 chars
Дата
Msg-id 4CBA1433.4040008@gmail.com
обсуждение исходный текст
Ответ на Re: Constraint: string length must be 32 chars  (Merlin Moncure <mmoncure@gmail.com>)
Ответы Re: Constraint: string length must be 32 chars  (Alexander Farber <alexander.farber@gmail.com>)
Список pgsql-general

Merlin Moncure wrote:
> On Sat, Oct 16, 2010 at 12:15 PM, Alexander Farber
> <alexander.farber@gmail.com> wrote:
>
>> Hello,
>>
>> I'm trying to create a table, where md5 strings will serve as primary keys.
>> So I'd like to add a constraing that the key length should be 32 chars long
>> (and contain [a-fA-F0-9] only):
>>
>
> why don't you use the bytea type, and cut the key size down 50%?  You
> can always format it going out the door if you want it displayed hex.
> Besides being faster, you get to skip the 'is hex' regex.
>
> create table foo(id bytea check(length(id) = 16));
> insert into foo values (decode(md5('a'), 'hex')); -- if not using pgcrypto
> insert into foo values (digest('b', 'md5')); -- if using pgcrypto (preferred)
>
> select encode(id, 'hex') from foo;
>
> merlin
>
>

Why not the support uuid type instead.  Aren't md5s only as unique as
the source?  i.e. The same value hashed results in the same md5, no?

В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Constraint: string length must be 32 chars
Следующее
От: Alexander Farber
Дата:
Сообщение: Re: Constraint: string length must be 32 chars