Re: NEXT VALUE FOR sequence

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "Laurenz Albe" <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-hackers(at)postgresql(dot)org,hs(at)cybertec(dot)at
Subject: Re: NEXT VALUE FOR sequence
Date: 2018-02-19 13:21:47
Message-ID: 759ae1b7-543c-4f38-9bc9-cbe773cbe5ef@manitou-mail.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Laurenz Albe wrote:

> The SQL standard has the expression "NEXT VALUE FOR asequence" to do
> what we traditionally do with "nextval('asequence')".

The behavior mandated by the standard is that several invocations
of NEXT VALUE on the same sequence on the same output row
must produce the same value. That is:

CREATE SEQUENCE s;
SELECT NEXT VALUE FOR s, NEXT VALUE FOR s
UNION
SELECT NEXT VALUE FOR s, NEXT VALUE FOR s

should produce
(1,1)
(2,2)

It makes sense that the value does not depend on
the position of the expression as a column.

The trouble of course is that the equivalent with
nextval() would produce instead
(1,2)
(3,4)

There have been previous discussions on the standard syntax
that said that when it will get into postgres, it should go with
the standard conforming semantics.
I guess it would be a much more difficult patch.

Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2018-02-19 13:40:46 Re: [HACKERS] path toward faster partition pruning
Previous Message Alexander Levsha 2018-02-19 12:37:21 Tracking object modification time using event triggers