Re: execute same query only one time?
От | Vitaly Burovoy |
---|---|
Тема | Re: execute same query only one time? |
Дата | |
Msg-id | CAKOSWNn+Cq5Rq02chFtDmXHo5ciACFetxotvBVtk0BP0MAkA6g@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: execute same query only one time? (Johannes <jotpe@posteo.de>) |
Ответы |
Re: execute same query only one time?
|
Список | pgsql-general |
On 2/8/16, Johannes <jotpe@posteo.de> wrote: > > Am 08.02.2016 um 20:32 schrieb Vitaly Burovoy: >> On 2/8/16, Adrian Klaver <adrian.klaver@aklaver.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
В списке pgsql-general по дате отправления: