Re: Bug? Function with side effects not evaluated in CTE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Moshe Jacobson <moshe(at)neadwerx(dot)com>
Cc: David Johnston <polobo(at)yahoo(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Bug? Function with side effects not evaluated in CTE
Date: 2013-10-21 18:53:49
Message-ID: 2651.1382381629@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Moshe Jacobson <moshe(at)neadwerx(dot)com> writes:
> I am of the belief that if the function in a CTE is volatile, that it
> should be executed unconditionally.

[ shrug... ] Consider

SELECT volatile_function(i) FROM generate_series(1, 10) i LIMIT 1;

How many times should the volatile function get executed? If your answer
is not "10", how is this different from the CTE case? This LIMIT clause
is restricting the number of times the function executes in pretty much
the same way that our definition of CTE evaluation does, AFAICS.

You could of course argue that our definition of LIMIT is wrong too,
but that's going to raise the bar for convincing people even higher,
because of the number of existing applications that such a redefinition
would break.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message ramistuni 2013-10-21 19:00:08 Re: Upgrade from 9.1 to 9.10
Previous Message Tom Lane 2013-10-21 18:46:24 Re: locks held during commit with synchronous replication