Re: Get last generated serial sequence and set it up when explicit value is used
От | David G. Johnston |
---|---|
Тема | Re: Get last generated serial sequence and set it up when explicit value is used |
Дата | |
Msg-id | CAKFQuwY6oxAPp+QFsK2No5q6984rNWaBy-rQ3nRQJ2gf4_etPw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Get last generated serial sequence and set it up when explicit value is used (Sebastien FLAESCH <sf@4js.com>) |
Ответы |
Re: Get last generated serial sequence and set it up when explicit value is used
|
Список | pgsql-sql |
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.
В списке pgsql-sql по дате отправления: