From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Moshe Jacobson <moshe(at)neadwerx(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Bug? Function with side effects not evaluated in CTE |
Date: | 2013-10-16 23:06:53 |
Message-ID: | CAHyXU0x9cinvW8Vkc_tGvCK-DNUFkg+R3Z9ABWCF5sVM6je-Jg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Oct 16, 2013 at 4:26 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Moshe Jacobson <moshe(at)neadwerx(dot)com> writes:
>> However, It behaves as one would expect if the first CTE is built with INSERT
>> ... RETURNING.
>
> CTEs containing INSERT/UPDATE/DELETE are guaranteed to be executed exactly
> once. CTEs containing SELECTs are guaranteed to be executed at most once
> (the documentation phrases that as "execution can stop early if the outer
> query doesn't read all the rows" --- in this case, it read none of them,
> since the outer query never had to evaluate the NOT IN).
>
> I see no bug here.
You can force the CTE to be read a couple of different ways; it isn't
very difficult to do: just tweak the final query so that it *must*
touch the SELECT result somehow (e.g. AND (SELECT COUNT(*) FROM
tt_created) > 0).
That being said, I do think it might be better behavior (and still
technically correct per the documentation) if volatile query
expressions were force-evaluated.
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Nur Hidayat | 2013-10-16 23:10:28 | Re: PostgreSQL vs Mongo |
Previous Message | Adrian Klaver | 2013-10-16 22:28:58 | Re: pg_hba.conf broken after cluster upgrade |