Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr5Z7-00047l-Ea for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Dec 2013 12:40:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vr5Z6-0002BA-Rj for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Dec 2013 12:40:28 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr5Z5-0002B3-Rt for pgsql-bugs@postgresql.org; Thu, 12 Dec 2013 12:40:28 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr5Yz-0007ad-8h for pgsql-bugs@postgresql.org; Thu, 12 Dec 2013 12:40:27 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vr5Yy-00016U-Ni for pgsql-bugs@postgresql.org; Thu, 12 Dec 2013 12:40:21 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1Vr5Yt-0006cV-6e for pgsql-bugs@postgresql.org; Thu, 12 Dec 2013 12:40:15 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8678: Multiple evaluation single volatile function in select statement To: pgsql-bugs@postgresql.org From: maxim.boguk@gmail.com Message-Id: Date: Thu, 12 Dec 2013 12:40:15 +0000 X-Pg-Spam-Score: 0.9 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8678 Logged by: Maksym Email address: maxim.boguk@gmail.com PostgreSQL version: 9.3.2 Operating system: Linux Description: Hi everyone, One of my client got the problem of multiple-evaluation of the single volatile function call. Simplified test case: CREATE OR REPLACE FUNCTION _test1(OUT val1 float, OUT val2 float) AS $BODY$ DECLARE _val float; BEGIN _val := random(); val1 := _val; val2 := _val; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; Now good case: select * from _test1(); val1 | val2 -------------------+------------------- 0.616893119178712 | 0.616893119178712 Wrong case: select (_test1()).*; val1 | val2 ------------------+------------------- 0.54869711631909 | 0.251445888541639 Wrong case hits especially painful when volatile function performs some modification of the money-related data. PS: yes I know such query could be rewritten via LATERAL but it doesn't make current behavior more correct. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs