pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: maxim.boguk@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #8678: Multiple evaluation single volatile function in select statement
Date: Thu, 12 Dec 2013 12:40:15 +0000
Message-ID: <E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)  latest in thread

Message-ID: <E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org>
Permalink:  ../E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: maxim.boguk@gmail.com
  Subject: Re: BUG #8678: Multiple evaluation single volatile function in select statement
  In-Reply-To: <E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org>
  References: <E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox