Re: Object Relational, Foreign Keys and Triggers

From: Alex Turner <armtuk(at)gmail(dot)com>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>, alex(at)neteconomist(dot)com, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Object Relational, Foreign Keys and Triggers
Date: 2005-01-25 13:36:53
Message-ID: 33c6269f050125053629f5f66e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Actualy max() works just fine. It's not the solution I use in the
middle tier, but it works for a functional example. both max() and
currval() are bad because they can cause a race condition where the
sequence has been incremented by another thread. It's always better
to get nextval('sequence') and store it in a local var, then use it in
the main insert and corresponding sub-inserts.

The example I give has been tested, and works, it's not fake.

Alex Turner
NetEconomist

On Tue, 25 Jan 2005 09:23:31 +0100, Martijn van Oosterhout
<kleptog(at)svana(dot)org> wrote:
> On Mon, Jan 24, 2005 at 07:22:32PM -0500, Alex Turner wrote:
> > I am facing the classic pgsql ORDBMS problem:
>
> <snip>
>
> Why are you using MAX()? That won't work at all. Perhaps you need to
> look up the documentation for nextval and currval. In particular, that
> second query should be:
>
> insert into entity_phone select currval('entity_id_seq'),'610 495 5000';
>
> Also, I'm not sure if inheritance works quite the way you think in the
> example you give, though other people may correct me on that.
>
> Hope this helps,
> --
> Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> > tool for doing 5% of the work and then sitting around waiting for someone
> > else to do the other 95% so you can sue them.
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2005-01-25 13:44:13 Re: EMBEDDED PostgreSQL
Previous Message Peter Eisentraut 2005-01-25 13:20:45 Re: EMBEDDED PostgreSQL