Re: Drawbacks of using BYTEA for PK? - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Drawbacks of using BYTEA for PK?
Date
Msg-id 20040113155138.GA26266@wolff.to
Whole thread Raw
In response to Re: Drawbacks of using BYTEA for PK?  ("D. Dante Lorenso" <dante@lorenso.com>)
List 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.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Nested transaction workaround?
Next
From: Tom Lane
Date:
Subject: Re: insertion with trigger failed unexpectedly