Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1elEWd-0007BB-33 for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Feb 2018 13:52:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1elEWb-0005H0-Sc for pgsql-bugs@arkaria.postgresql.org; Mon, 12 Feb 2018 13:52:05 +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.84_2) (envelope-from ) id 1elEIt-000777-UD for pgsql-bugs@lists.postgresql.org; Mon, 12 Feb 2018 13:37:55 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1elEIo-0007LD-JJ for pgsql-bugs@postgresql.org; Mon, 12 Feb 2018 13:37:54 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id A4B9BB1D1445 for ; Mon, 12 Feb 2018 06:37:47 -0700 (MST) Date: Mon, 12 Feb 2018 06:37:47 -0700 (MST) From: Mark Scheffer To: pgsql-bugs@postgresql.org Message-ID: <1518442667671-0.post@n3.nabble.com> In-Reply-To: <151844034484.1446.1721073839109092583@wrigleys.postgresql.org> References: <151844034484.1446.1721073839109092583@wrigleys.postgresql.org> Subject: Re: BUG #15060: Row in table not found when using pg function in an expression MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form wrote > I tested this in postgresql versions 9.1, 10.1 and 10.2 on centOS. > > In short this is what happens (in a plpgsql function): > 1.) An insert is done into 'bug' table > 2.) A SELECT is done to make sure the INSERT was successful > 3.) Another function (get_bug_id) is called which returns id based on > value. > When the function is called directly, it returns the id correctly. When > it's > called in an expression, it does not find the inserted row and an > exception > is raised. Significant is that function get_bug_id() being STABLE is necessary for the bug to occur. It appears to be not a bug, since documentation reads: > For functions written in SQL or in any of the standard procedural > languages, there is a second important property determined by the > volatility category, * > namely the visibility of any data changes that have been made by the SQL > command that is calling the function. A VOLATILE function will see such > changes, a STABLE or IMMUTABLE function will not * > . This behavior is implemented using the snapshotting behavior of MVCC > (see Chapter 13): STABLE and IMMUTABLE functions use a snapshot > established as of the start of the calling query, whereas VOLATILE > functions obtain a fresh snapshot at the start of each query they execute. Although i.m.o. it is strange that one produces the proper result and the other call does not. -- Sent from: http://www.postgresql-archive.org/PostgreSQL-bugs-f2117394.html