Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgBuX-0002qK-U7 for pgsql-general@arkaria.postgresql.org; Thu, 19 Jul 2018 16:36:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fgBuT-0001VY-B0 for pgsql-general@arkaria.postgresql.org; Thu, 19 Jul 2018 16:36:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgBuR-0001VR-O2 for pgsql-general@lists.postgresql.org; Thu, 19 Jul 2018 16:36:09 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgBuL-000327-B4 for pgsql-general@postgresql.org; Thu, 19 Jul 2018 16:36:07 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id B109042E; Thu, 19 Jul 2018 12:35:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 19 Jul 2018 12:35:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=AHoIeKkVXlSoyRhKx4Ht2MH8t/ZXX uFl51N0f0201wQ=; b=ZTjnqK8V2dP30JYYpfqawvuF6PTAsjgMxhfRtrHKDHZun 56UT2abbr73vvEmdK3HxzVbg/K7Cz4rxgZE93U0yKNAkvbTHmRD6PXtx6rGBBCss R1Si9wCvhyGwtgGblgSw/BoDZluPCeVOQEC4N8TWQIXyM8PWf6gJVCOL+943z3DB 68fPRaGZ13FF0SiUA4Ez+xMFwVWq1rIy5owdL1tB9rn9pJIk8POk4h7TPljm+ZWC MietetITKlsf7UW/lwF6FXtv9gMzZtCP1McdFqQBw5EglYQLDc1zbzrq0eyYJAnE JLCcsvtzBzVFPau8l0sXiFJSVgID4Qvc7XP01+swQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=AHoIeK kVXlSoyRhKx4Ht2MH8t/ZXXuFl51N0f0201wQ=; b=t//nSgISxh+Yx4Sf7zYE+b y1gQw1c6jqTs0MAbSvNg4tZtq0NifhMpLNdtJ469N6B0b9NOSr1DR7W9/hOKCSh8 f2XmNuCSKEk3rUM9hsOnQxtMiWjpH/ZracMLyA12pq2+kFt7HolrssY4IYqNNDa5 wx5olBxUph8UAC+P6JYMI4aAUEXPUwnFcGQdo+pCzYy6FSIONr3B9qIG35+OIyNS OdseX55c8QO4gH/ntiA8554Uf1EVyY/a8gburP3+GEk+zPPPWydIw9QNAshJoq9c e9pXQVpcRfbvB3kiF3vyB/0JEtuTQprxQLX1ZxPZrIX9CIlLK+Nlg75QYSzsJ9Dg == X-ME-Proxy: X-ME-Sender: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 7417CE450F; Thu, 19 Jul 2018 12:35:55 -0400 (EDT) Subject: Re: functions with side effect To: =?UTF-8?Q?Torsten_F=c3=b6rtsch?= , PostgreSQL mailing lists References: From: Adrian Klaver Message-ID: Date: Thu, 19 Jul 2018 09:35:54 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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