<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 14, 2014 at 8:32 PM, Marco van de Voort <span dir="ltr"><<a href="mailto:marcov@stack.nl" target="_blank">marcov@stack.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Nov 14, 2014 at 03:11:30PM +0100, Michael Van Canneyt wrote:<br>
><br>
> By the very nature of the problem: GetLastAutoIncValue simply cannot be implemented in general.<br>
><br>
> In firebird, postgres,<br>
<br>
(and Oracle afaik)<br>
<br>
> these values are generated using a generator/sequence.<br>
> You don't know the name of the generator, and even if you did, it is impossible<br>
> to retrieve the value that was used to fill your particular record because the<br>
> sequence/generator may have been updated several thousands of times by the time<br>
> your second statement arrives.<br>
<br>
IIRC the currval from a sequence is per session, so if you didn't insert<br>
again in the same transaction that is ok too.<br>
<br>
Moverover there is lastval to avoid knowing the sequence name<br>
<br>
from <a href="http://www.postgresql.org/docs/8.4/static/functions-sequence.html" target="_blank">http://www.postgresql.org/docs/8.4/static/functions-sequence.html</a><br>
<br>
lastval<br>
<br>
Return the value most recently returned by nextval in the current<br>
session. This function is identical to currval, except that instead of<br>
taking the sequence name as an argument it fetches the value of the last<br>
sequence used by nextval in the current session. It is an error to call<br>
lastval if nextval has not yet been called in the current session.</blockquote></div><div class="gmail_extra"><br></div><div class="gmail_extra">And PostgreSQL provides the RETURNING feature too. =)</div><div class="gmail_extra"><br></div>--<br><div class="gmail_signature">Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>