Re: functions with side effect - Mailing list pgsql-general

From Adrian Klaver
Subject Re: functions with side effect
Date
Msg-id ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com
Whole thread Raw
In response to functions with side effect  (Torsten Förtsch <tfoertsch123@gmail.com>)
Responses Re: functions with side effect  (Torsten Förtsch <tfoertsch123@gmail.com>)
List pgsql-general
On 07/19/2018 07:15 AM, Torsten Förtsch wrote:
> Hi,
> 
> assuming
> 
> SELECT nextval('s'), currval('s');
> 
> or
> 
> SELECT * FROM (VALUES (nextval('s'), currval('s'))) t;
> 
> is there any guarantee that the 2 output values are the same?

Assuming you are only working in single session:

https://www.postgresql.org/docs/10/static/functions-sequence.html

"currval

     Return the value most recently obtained by nextval for this 
sequence in the current session. (An error is reported if nextval has 
never been called for this sequence in this session.) Because this is 
returning a session-local value, it gives a predictable answer whether 
or not other sessions have executed nextval since the current session did."

> 
> Thanks,
> Torsten


-- 
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Alessandro Aste
Date:
Subject: Re: cache lookup failed for attribute 1 of relation XXXXXX
Next
From: Torsten Förtsch
Date:
Subject: Re: functions with side effect