From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Sebastien FLAESCH <sf(at)4js(dot)com> |
Cc: | pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Get last generated serial sequence and set it up when explicit value is used |
Date: | 2020-11-20 08:49:44 |
Message-ID: | CAKFQuwY6oxAPp+QFsK2No5q6984rNWaBy-rQ3nRQJ2gf4_etPw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Friday, November 20, 2020, Sebastien FLAESCH <sf(at)4js(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Sebastien FLAESCH | 2020-11-20 10:23:24 | Re: Get last generated serial sequence and set it up when explicit value is used |
Previous Message | Sebastien FLAESCH | 2020-11-20 08:19:57 | Re: Get last generated serial sequence and set it up when explicit value is used |