[GENERAL] sequence used on null value or get the max value for a column whithconcurrency - Mailing list pgsql-general

From marcelo
Subject [GENERAL] sequence used on null value or get the max value for a column whithconcurrency
Date
Msg-id 5e114139-d4d8-b402-3a0c-b82f1ebfa5f8@gmail.com
Whole thread Raw
Responses Re: [GENERAL] sequence used on null value or get the max value for acolumn whith concurrency  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: [GENERAL] sequence used on null value or get the max value fora column whith concurrency  (rob stone <floriparob@gmail.com>)
List pgsql-general
In some table, I have a bigint column which at the app level can be
null. Call it "DocumentNumber", and of course is not the PK.
In most cases, the applications give some value to the column.

But sometimes, the value remains null, expecting the backend or someone
assign it a unique value.

Could I use a sequence only when the field arrives to the backend as
null? How? Using a triger?

Alternatively:

How could I get the max value for the column and increment it by one,
but with concurrency warranty? Something as a table lock?

TIA





pgsql-general by date:

Previous
From: armand pirvu
Date:
Subject: Re: [GENERAL] pglogical sync
Next
From: "David G. Johnston"
Date:
Subject: Re: [GENERAL] sequence used on null value or get the max value for acolumn whith concurrency