Re: Planner features, discussion

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
Cc: David Fetter <david(at)fetter(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Planner features, discussion
Date: 2010-07-15 09:55:51
Message-ID: BF63C95B-248A-4E63-BF49-33A63C15A996@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 15 Jul 2010, at 3:05, Craig Ringer wrote:

> It was an example of how it'd be nice to avoid the need for a join when
> dealing with scalar values. I'd love to be able to write:
>
> WITH aconstant AS (1)
> SELECT x.*, aconstant FROM generate_series(1,10) AS x;
>
> ... but can't presently do so because the WITH terms are only visible as
> potential from-list items.

But why is that a problem? The below seems to work just fine:

dalroi=> WITH constants AS (SELECT 1 AS aconstant)
SELECT 'x' AS column, aconstant FROM constants WHERE aconstant = 1;
column | aconstant
--------+-----------
x | 1
(1 row)

Sure, you'll have to join with the with-query to get any meaningful results, but if there are any complicated calculations in that query, won't they be calculated just once - like you intended?

If not, I think we're all failing to see the point you're trying to make.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4c3edb34286212005648618!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2010-07-15 09:59:01 Re: Planner features, discussion
Previous Message Vincenzo Romano 2010-07-15 09:55:22 Inheritance efficiency