From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Gabriel Sánchez <gabrielesanchez@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Unused CTE affects result set
Date: Fri, 17 Nov 2023 10:35:22 -0800
Message-ID: <c535bd22-690f-418a-b956-a4d3602a7af4@aklaver.com> (raw)
In-Reply-To: <CANHuRqHUR+a0TEF7WXLNN1+_=6CjET-jtu=QFuEPJ875oMHC7A@mail.gmail.com>
References: <CANHuRqHUR+a0TEF7WXLNN1+_=6CjET-jtu=QFuEPJ875oMHC7A@mail.gmail.com>
On 11/17/23 10:30 AM, Gabriel Sánchez wrote:
> Dear Postgres community,
>
> I'm seeing unintuitive behavior with a query structured as follows:
>
> WITH used_cte (SELECT a, b, c FROM t1 ...)
> , unused_cte (SELECT d, e, f FROM t2 ...)
> SELECT * FROM used_cte ...
> -- returns no results
>
> WITH used_cte (SELECT a, b, c FROM t1 ...)
> -- , unused_cte (SELECT d, e, f FROM t2 ...)
> SELECT * FROM used_cte ...
> -- returns results
>
> I don't understand why the presence of a CTE that ends up not being
> included in the final query affects the result set. Could this be a
> bug, or is there something I don't understand?
I would say it has to do with what '...' is doing?
In other words I don't see this behavior here for a simple case.
>
> PostgreSQL 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu,
> compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
>
> Thanks,
> Gabriel
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, gabrielesanchez@gmail.com
Subject: Re: Unused CTE affects result set
In-Reply-To: <c535bd22-690f-418a-b956-a4d3602a7af4@aklaver.com>
References: <CANHuRqHUR+a0TEF7WXLNN1+_=6CjET-jtu=QFuEPJ875oMHC7A@mail.gmail.com> <c535bd22-690f-418a-b956-a4d3602a7af4@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox