Re: "ownership" of sequences, pseudo random unique id

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: "ownership" of sequences, pseudo random unique id
Date: 2009-08-20 18:31:02
Message-ID: 20090820183102.GJ6261@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ivan Sergio Borgonovo wrote:
> I've
>
> create table pr(
> code varchar(16) primary key,
> ...
> );
> create sequence pr_code_seq owned by pr.code; -- uh!
>
> pr.code will *mostly* be obtained as
>
> to_hex(feistel_encrypt(nextval('pr_code')))
> and sometimes 'manually' inserting unique codes.
>
> actually stuff like:
> alter table pr drop column code;
> or just
> drop table pr
>
> seems to work as expected (they drop the sequence too).
>
> Should I be concerned of anything since it looks like a hack?

You need to ensure you have a retry loop in your insertion code, because
if the generated code conflicts with a manually inserted code, it will
cause an error. Other than that, seems like it should work ...

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Kempter 2009-08-20 19:18:26 locking/waiting queries
Previous Message Chris Hopkins 2009-08-20 18:23:45 Out of memory on pg_dump