Re: Drawbacks of using BYTEA for PK?

Bruno Wolff III <bruno@wolff.to>

From: Bruno Wolff III <bruno@wolff.to>
To: "D. Dante Lorenso" <dante@lorenso.com>
Cc: "Keith C. Perry" <netadmin@vcsn.com>, Greg Stark <gsstark@mit.edu>, pgsql-general@postgresql.org
Date: 2004-01-13T15:51:38Z
Lists: pgsql-general
On Mon, Jan 12, 2004 at 20:24:10 -0600,
  "D. Dante Lorenso" <dante@lorenso.com> wrote:
> 
> See what I mean?  What do you propose as the best solution for this?  
> Not expose
> the sequences to the user and use user-enumerated ids?  Then a trigger 
> on the
> table would assign ids like:
> 
>    SELECT (MAX(widget_id)+1) INTO NEW.widget_id
>    WHERE cust_id = NEW.cust_id;
> 
> But I think after several hundred customer records, this trigger would start
> getting slow.  I don't know really, any ideas?

I think it would be better to have a per customer counter. Then the GID
would be customer, customer_sequence. You probably wouldn't want to use
postgres sequences for this. I would expect that generating new ID numbers
isn't so common that updating a counter row in a customer counter table
would be a real problem.