From: | Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com> |
---|---|
To: | Johannes <jotpe(at)posteo(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: execute same query only one time? |
Date: | 2016-02-08 20:33:36 |
Message-ID: | CAKOSWNn+Cq5Rq02chFtDmXHo5ciACFetxotvBVtk0BP0MAkA6g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 2/8/16, Johannes <jotpe(at)posteo(dot)de> wrote:
>
> Am 08.02.2016 um 20:32 schrieb Vitaly Burovoy:
>> On 2/8/16, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> wrote:
>>> Based on rough guess of the above, without seeing actual table schemas:
>>>
>>> select id, t0.col1, t1.col1, col2, ... from t0 JOIN t1 ON t0.id =
>>> t1.t0_id where id = (select max(id) from t0 where col1 = value1 and col2
>>> = value2 and ...);
>>
>> I don't think it is a good solution because it leads to copying
>> columns from the t0 which is wasting net traffic and increasing
>> complexity at the client side. Moreover it works iff t0 returns only
>> one row.
>
> I had same doubts.
> CTE would be first class, if it was be reusable for other statements.
>
> Johannes
CTEs are temporary tables for a _statement_ for using a single
statement instead of several ones (create temp table, insert into,
select from it, select from it, drop temp table).
But it is not your case because CTEs are for a queries which return a
single set of rows. Your case is returning two sets (one row with
several columns from t0 and several rows with a single columns from
t1).
--
Best regards,
Vitaly Burovoy
From | Date | Subject | |
---|---|---|---|
Next Message | Johannes | 2016-02-08 20:46:05 | Re: execute same query only one time? |
Previous Message | Johannes | 2016-02-08 20:26:30 | Re: execute same query only one time? |