Albert REINER wrote:
>
> I do not know of a way to insert and select in one statement without
> the use of a function (what's the problem with those, by the way?),
> but as far as I can tell nextval() will return the next value for any
> backend, so if you have more than one backend inserting at the same
> time you might end up inserting with the same id twice. Instead you
Actually nextval() works fine across backends. It always increments the
sequence, so repeated calls waste numbers.
> should insert once, without specifying the id (so that the default
> value, which must be set to nextval()) will be used; to obtain the id,
> if indeed you need it, you can than select currval(), which is
> guaranteed to work on a per-backend basis.
Yep - it's either get nextval and insert or insert and check currval.
- Richard Huxton