Re: Invalid optimization of VOLATILE function in WHERE clause?

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "ktm(at)rice(dot)edu" <ktm(at)rice(dot)edu>, "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
Cc: "Florian Schoppmann" <Florian(dot)Schoppmann(at)emc(dot)com>, "Robert Haas" <robertmhaas(at)gmail(dot)com>,<pgsql-hackers(at)postgresql(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Invalid optimization of VOLATILE function in WHERE clause?
Date: 2012-09-19 20:30:34
Message-ID: 5059E51A020000250004A529@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:
> There is a workaround, if you don't mind ugly:

Or, better:

WITH source AS (
SELECT i, random() AS r FROM generate_series(1,10) AS i
)
SELECT
i
FROM
source, (
SELECT
count(*) AS _n
FROM source
) AS _stats
WHERE
r < 5::DOUBLE PRECISION/_n;

-Kevin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Johnston 2012-09-19 20:40:18 Re: Invalid optimization of VOLATILE function in WHERE clause?
Previous Message Kevin Grittner 2012-09-19 20:26:03 Re: Invalid optimization of VOLATILE function in WHERE clause?