Search Postgresql Archives

Re: execute same query only one time?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Am 08.02.2016 um 21:33 schrieb Vitaly Burovoy:
> On 2/8/16, Johannes <jotpe@xxxxxxxxx> wrote:
>>
>> Am 08.02.2016 um 20:32 schrieb Vitaly Burovoy:
>>> On 2/8/16, Adrian Klaver <adrian.klaver@xxxxxxxxxxx> 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).

Sure.
Thanks for the temporary table example!

Johannes


Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux