Re: functions with side effect

2018-07-19 Thread Torsten Förtsch
On Thu, Jul 19, 2018 at 8:10 PM Tom Lane wrote: > =?UTF-8?Q?Torsten_F=C3=B6rtsch?= writes: > > I know that. My question was about the execution order of f1 and f2 in > > "SELECT f1(), f2()". In theory they can be executed in any order. But > since > > the side effect in nextval determines the re

Re: functions with side effect

2018-07-19 Thread Tom Lane
=?UTF-8?Q?Torsten_F=C3=B6rtsch?= writes: > I know that. My question was about the execution order of f1 and f2 in > "SELECT f1(), f2()". In theory they can be executed in any order. But since > the side effect in nextval determines the result of currval, I am asking if > that order is well-defined

Re: functions with side effect

2018-07-19 Thread Adrian Klaver
On 07/19/2018 09:43 AM, Torsten Förtsch wrote: On Thu, Jul 19, 2018 at 6:35 PM Adrian Klaver > wrote: On 07/19/2018 07:15 AM, Torsten Förtsch wrote: > Hi, > > assuming > > SELECT nextval('s'), currval('s'); > > or >

Re: functions with side effect

2018-07-19 Thread Pavel Luzanov
Very interesting question. postgres=# create sequence s; CREATE SEQUENCE postgres=# select currval('s'), nextval('s'); ERROR:  currval of sequence "s" is not yet defined in this session postgres=# select nextval('s'), currval('s');  nextval | currval -+-    1 |   1 We see

Re: functions with side effect

2018-07-19 Thread Adrian Klaver
On 07/19/2018 09:43 AM, Torsten Förtsch wrote: On Thu, Jul 19, 2018 at 6:35 PM Adrian Klaver > wrote: On 07/19/2018 07:15 AM, Torsten Förtsch wrote: > Hi, > > assuming > > SELECT nextval('s'), currval('s'); > > or >

Re: functions with side effect

2018-07-19 Thread Torsten Förtsch
On Thu, Jul 19, 2018 at 6:35 PM Adrian Klaver wrote: > 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 valu

Re: functions with side effect

2018-07-19 Thread Adrian Klaver
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.or

Re: functions with side effect

2018-07-19 Thread Laurenz Albe
Torsten Förtsch wrote: > 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? You can use at EXPLAIN (VERBOSE) output to see if it will work in this special case, but