Re: Efficiently advancing a sequence without risking it going backwards.

2020-07-16 Thread Paul McGarry
On Fri, 10 Jul 2020 at 10:27, Jeremy Schneider wrote: > > OP asked for a way to call setval() with a guarantee the sequence will > never go backwards IIUC. His code can check that the new value he wants to > set is higher than the current value, but there’s a race condition where a > second conne

Re: Efficiently advancing a sequence without risking it going backwards.

2020-07-09 Thread Jeremy Schneider
>> On Jul 9, 2020, at 14:08, Christopher Browne wrote: >  >> On Thu, 9 Jul 2020 at 12:59, Jeremy Schneider >> wrote: > >> >> > On Jul 6, 2020, at 19:06, Paul McGarry wrote: >> > >> > I don't think I can use setval(), because it risks making sequences go >> > backwards, eg: >> > >> > 1)

Re: Efficiently advancing a sequence without risking it going backwards.

2020-07-09 Thread Tim Cross
Christopher Browne writes: > On Thu, 9 Jul 2020 at 12:59, Jeremy Schneider > wrote: > >> >> > On Jul 6, 2020, at 19:06, Paul McGarry wrote: >> > >> > I don't think I can use setval(), because it risks making sequences go >> backwards, eg: >> > >> > 1) Check values >> > DB1sequence: 1234 >> >

Re: Efficiently advancing a sequence without risking it going backwards.

2020-07-09 Thread Christopher Browne
On Thu, 9 Jul 2020 at 12:59, Jeremy Schneider wrote: > > > On Jul 6, 2020, at 19:06, Paul McGarry wrote: > > > > I don't think I can use setval(), because it risks making sequences go > backwards, eg: > > > > 1) Check values > > DB1sequence: 1234 > > DB2sequence: 1233 (1 behind) > > 2) setval('D

Re: Efficiently advancing a sequence without risking it going backwards.

2020-07-09 Thread Jeremy Schneider
> On Jul 6, 2020, at 19:06, Paul McGarry wrote: > > I don't think I can use setval(), because it risks making sequences go > backwards, eg: > > 1) Check values > DB1sequence: 1234 > DB2sequence: 1233 (1 behind) > 2) setval('DB2sequence',1234); > > but if between (1) and (2) there are 2 nextv

Re: Efficiently advancing a sequence without risking it going backwards.

2020-07-06 Thread Adrian Klaver
On 7/6/20 7:06 PM, Paul McGarry wrote: I have two sequences in different dbs which I want to keep roughly in sync (they don't have to be exactly in sync, I am just keeping them in the same ballpark). Currently I have a process which periodically checks the sequences and does: 1) Check values