On Friday, November 20, 2020, Sebastien FLAESCH <
sf@4js.com> wrote:
Is there any way to avoid the error produced by currval()?
No
Ideally, currval() should return zero when no serial was produced yet.
I’d accept null, zero is a valid value.
Is it possible to write that in a simple SQL expression so it can be used in
the RETURNING clause of my INSERTs ?
Not that I can think of. Maybe as the docs suggest, just do an unconditional setval()? You might be able to combine that with a non-default isolation level (guessing here) to get close-enough behavior. You are fighting the existing design of the feature, looking for an in-between position of fast-and-concurrent (existing) and fully serialized (where this would be mostly trivial to implement). I don’t know of such a method.
David J.