BUG #8678: Multiple evaluation single volatile function in select statement

From: maxim(dot)boguk(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #8678: Multiple evaluation single volatile function in select statement
Date: 2013-12-12 12:40:15
Message-ID: E1Vr5Yt-0006cV-6e@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 8678
Logged by: Maksym
Email address: maxim(dot)boguk(at)gmail(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2013-12-12 16:48:51 Re: BUG #8677: char(n) - bad limit with arrays of composite type
Previous Message Tom Lane 2013-12-12 03:12:53 Re: xlog.c has executable permission in git