pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Torsten Förtsch <tfoertsch123@gmail.com>
To: PostgreSQL mailing lists <pgsql-general@postgresql.org>
Subject: Re: functions with side effect
Date: Thu, 19 Jul 2018 09:35:54 -0700
Message-ID: <ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com> (raw)
In-Reply-To: <CAKkG4_=MTjK6bAJDLM8brKR+U6JggZNhEta6nXgANUyWo8VcDA@mail.gmail.com>
References: <CAKkG4_=MTjK6bAJDLM8brKR+U6JggZNhEta6nXgANUyWo8VcDA@mail.gmail.com>

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




view thread (9+ messages)  latest in thread

Message-ID: <ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com>
Permalink:  ../ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com/
Also on:    postgresql.org/message-id/ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, tfoertsch123@gmail.com
  Subject: Re: functions with side effect
  In-Reply-To: <ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com>
  References: <CAKkG4_=MTjK6bAJDLM8brKR+U6JggZNhEta6nXgANUyWo8VcDA@mail.gmail.com> <ebb85d10-94a2-505a-8e8e-d4bf2f59e5f8@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox