Re: BUG #7786: select from view is computing columns not selected

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: doug(at)oakstreetsoftware(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7786: select from view is computing columns not selected
Date: 2013-01-04 18:03:07
Message-ID: 22106.1357322587@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

doug(at)oakstreetsoftware(dot)com writes:
> in the interest of simplicity, I've got a view that calls a stored procedure
> to compute a value ...

> create view testv as select tt.field1, tt.intfield, compute_val(tt.field1)
> AS compute1 from tt;

> If compute_val() selects sum(intfield) from the testv view, compute_val() is
> called again when selecting records from testv (even though compute1 was not
> selected), resulting in infinite recursion (stack overflow).

> In retrospect, I realize this may have been a bad thing to do, but it worked
> in version 8.1.x.

I suspect that your function is declared VOLATILE, possibly by default.
PG versions later than 8.1 refrain from flattening views that contain
volatile functions in their SELECT list, on the grounds that such a
transformation might remove side-effects that the user expects to have
happen, or even cause the side-effects to happen more often than expected.

If you can declare the function STABLE then the view should continue to
work as before.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message gdurbin 2013-01-04 19:31:25 BUG #7787: ERROR: could not find RelOptInfo for given relids
Previous Message Tom Lane 2013-01-04 17:30:44 Re: BUG #7785: Bad plan for UNION ALL view containing JOIN