Re: CTEs and re-use

From: Rosser Schwarz <rosser(dot)schwarz(at)gmail(dot)com>
To: Rob Sargent <robjsargent(at)gmail(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: CTEs and re-use
Date: 2017-04-12 04:04:22
Message-ID: CAFnxYwhpbiPJo6-To8oHw5NgA3TvaA2EUxma=QjjYDVvAB2ZQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Apr 11, 2017 at 5:41 PM, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:

> I have a lovely little CTE/select doing exactly what I need it to do.
> Unfortunately I need its results in the next query.

Can't you just chain the CTEs? E.g.,

with segset as (
--...
)
, optmarkers as (
select m.id as mkrid
--...
group by m.id
)
select s.id, o.optval, min(m.basepos) as firstbase
from optmarkers o
--...
order by firstbase;

No temp table to drop.

rls

--
:wq

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Rob Sargent 2017-04-12 16:29:25 Re: CTEs and re-use
Previous Message Rob Sargent 2017-04-12 03:05:36 Re: CTEs and re-use