Re: possible race condition in trigger functions on insert operations?

From: Kenneth Tilton <ktilton(at)mcna(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: David Johnston <polobo(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: possible race condition in trigger functions on insert operations?
Date: 2011-11-22 20:56:36
Message-ID: CAECCA8YeH6TmTUFoYKVf5cZaAdJ-WFc_2e0JVg-X9CTfR6uTqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Nov 22, 2011 at 3:52 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Tue, Nov 22, 2011 at 2:43 PM, David Johnston <polobo(at)yahoo(dot)com> wrote:
>> Just create a single sequence for each year and then call the proper one
>> on-the-fly.  You can create multiple sequences in advance and possible even
>> auto-create the sequence the first time one is attempted to be used in a
>> given year.  If you can live with possible (but probably unlikely) gaps in
>> the sequence then all the concurrency will be handled for you and you can
>> focus on writing a function that, given a year, will return the proper
>> value.
>
> I personally think the 'record the next to be inserted value' in a
> table somewhere is better unless you are trying to support a lot of
> concurrent operations.  Also the gap issue is more likely to come up
> than you're letting on -- a rolled back transaction is all it takes.

Yeah, using a table seems to have the advantage of being about the
only thing that would work, though I think row_number properly used
(with an invariant ordering and no deletes) also works.

-kenneth

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2011-11-22 21:28:03 Re: Incremental backup with RSYNC or something?
Previous Message Kenneth Tilton 2011-11-22 20:54:14 Re: possible race condition in trigger functions on insert operations?