Re: [GENERAL] execute same query only one time?

2016-02-09 Thread Vitaly Burovoy
On 2/9/16, Johannes wrote: > Am 09.02.2016 um 00:56 schrieb Vitaly Burovoy: >> On 2/8/16, Johannes wrote: >>> Am 08.02.2016 um 21:50 schrieb Vitaly Burovoy: On 2/8/16, Johannes wrote: > increase speed, Speed will be at least the same. In your case either you have to use m

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread Johannes
Am 09.02.2016 um 00:56 schrieb Vitaly Burovoy: > On 2/8/16, Johannes wrote: >> Am 08.02.2016 um 21:50 schrieb Vitaly Burovoy: >>> On 2/8/16, Johannes wrote: Am 08.02.2016 um 21:17 schrieb Vitaly Burovoy: > Hmm. Could you clarify why you don't want to pass id from the first > query

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread Vitaly Burovoy
On 2/9/16, Marc Mamin wrote: > > Hi, > > is there a best practice to share data between two select statements? > > Hi, > I didn't check the whole thread Try it[1]. The thread is not so long (21 letters before yours) and it worth it. > so forgive me if this was already proposed, > but

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread David G. Johnston
On Tue, Feb 9, 2016 at 12:16 PM, Marc Mamin wrote: > > Hi, > > is there a best practice to share data between two select statements? > > Hi, > I didn't check the whole thread so forgive me if this was already proposed, > but maybe you could do something like: > > create temp table

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread Marc Mamin
Hi, is there a best practice to share data between two select statements? Hi, I didn't check the whole thread so forgive me if this was already proposed, but maybe you could do something like: create temp table result2 (...) query_1: WITH cte as (select ..), tmp as ( INSERT INTO

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread David G. Johnston
On Tuesday, February 9, 2016, Vitaly Burovoy wrote: > On 2/9/16, Harald Fuchs > wrote: > > Johannes > writes: > > > >>> What the reason to execute all statements which return different > >>> columns at once? > >>> > Saving roundtrips, > >>> > >>> In most cases they are not so big. Getting a

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread Vitaly Burovoy
On 2/9/16, Harald Fuchs wrote: > Johannes writes: > >>> What the reason to execute all statements which return different >>> columns at once? >>> Saving roundtrips, >>> >>> In most cases they are not so big. Getting a bunch of duplicated data >>> is wasting you network bandwidth and don't in

Re: [GENERAL] execute same query only one time?

2016-02-09 Thread Harald Fuchs
Johannes writes: >> What the reason to execute all statements which return different >> columns at once? >> >>> Saving roundtrips, >> >> In most cases they are not so big. Getting a bunch of duplicated data >> is wasting you network bandwidth and don't increase speed. > > In my and your example

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Johannes wrote: > Am 08.02.2016 um 21:50 schrieb Vitaly Burovoy: >> On 2/8/16, Johannes wrote: >>> Am 08.02.2016 um 21:17 schrieb Vitaly Burovoy: Hmm. Could you clarify why you don't want to pass id from the first query to the second one: select col1 from t1 where t

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Johannes
Am 08.02.2016 um 21:50 schrieb Vitaly Burovoy: > On 2/8/16, Johannes wrote: >> Am 08.02.2016 um 21:17 schrieb Vitaly Burovoy: >>> On 2/8/16, Johannes wrote: Am 08.02.2016 um 20:15 schrieb David G. Johnston: > On Mon, Feb 8, 2016 at 12:05 PM, Johannes wrote: > >> Hi, >> >>>

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Alban Hertroys wrote: > >> On 08 Feb 2016, at 20:05, Johannes wrote: >> >> select id, col1, col2, ... from t0 where id = (select max(id) from t0 >> where col1 = value1 and col2 = value2 and …); >> >> select col1 from t1 where t0_id = (select max(id) from t0 where col1 = >> value1 and c

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Johannes wrote: > Am 08.02.2016 um 21:17 schrieb Vitaly Burovoy: >> On 2/8/16, Johannes wrote: >>> Am 08.02.2016 um 20:15 schrieb David G. Johnston: On Mon, Feb 8, 2016 at 12:05 PM, Johannes wrote: > Hi, > > is there a best practice to share data between two sele

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Alban Hertroys
> On 08 Feb 2016, at 20:05, Johannes wrote: > > select id, col1, col2, ... from t0 where id = (select max(id) from t0 > where col1 = value1 and col2 = value2 and …); > select col1 from t1 where t0_id = (select max(id) from t0 where col1 = > value1 and col2 = value2 and …); select t0.id, t0.co

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Johannes
Am 08.02.2016 um 21:33 schrieb Vitaly Burovoy: > On 2/8/16, Johannes wrote: >> >> Am 08.02.2016 um 20:32 schrieb Vitaly Burovoy: >>> On 2/8/16, Adrian Klaver wrote: Based on rough guess of the above, without seeing actual table schemas: select id, t0.col1, t1.col1, col2, ... from

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Johannes wrote: > > Am 08.02.2016 um 20:32 schrieb Vitaly Burovoy: >> On 2/8/16, Adrian Klaver 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 ma

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Johannes
Am 08.02.2016 um 21:17 schrieb Vitaly Burovoy: > On 2/8/16, Johannes wrote: >> Am 08.02.2016 um 20:15 schrieb David G. Johnston: >>> On Mon, Feb 8, 2016 at 12:05 PM, Johannes wrote: >>> Hi, is there a best practice to share data between two select statements? Imaging fo

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Johannes
Am 08.02.2016 um 20:32 schrieb Vitaly Burovoy: > On 2/8/16, Adrian Klaver wrote: >> On 02/08/2016 11:05 AM, Johannes wrote: >>> Imaging following situation: I want to receive two result sets from two >>> tables, referring to a specific id from table t0 AND I try not to query >>> for that specifi

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Johannes wrote: > Am 08.02.2016 um 20:15 schrieb David G. Johnston: >> On Mon, Feb 8, 2016 at 12:05 PM, Johannes wrote: >> >>> Hi, >>> >>> is there a best practice to share data between two select statements? >>> >>> Imaging following situation: I want to receive two result sets from t

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Johannes
Am 08.02.2016 um 20:15 schrieb David G. Johnston: > On Mon, Feb 8, 2016 at 12:05 PM, Johannes wrote: > >> Hi, >> >> is there a best practice to share data between two select statements? >> >> Imaging following situation: I want to receive two result sets from two >> tables, referring to a specifi

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
x27;t subscribed to the list. > -Original Message- > From: Johannes > To: pgsql-general@postgresql.org > Sent: Mon, 08 Feb 2016 11:07 > Subject: [GENERAL] execute same query only one time? > > Hi, > > is there a best practice to share data between two select stat

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Adrian Klaver wrote: > On 02/08/2016 11:05 AM, Johannes wrote: >> Imaging following situation: I want to receive two result sets from two >> tables, referring to a specific id from table t0 AND I try not to query >> for that specific id a second time. > >> Table t0 returns 1 row and tab

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Vitaly Burovoy
On 2/8/16, Johannes wrote: > Hi, > > is there a best practice to share data between two select statements? > > Imaging following situation: I want to receive two result sets from two > tables, referring to a specific id from table t0 AND I try not to query > for that specific id a second time. > >

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread Adrian Klaver
On 02/08/2016 11:05 AM, Johannes wrote: Hi, is there a best practice to share data between two select statements? A join: http://www.postgresql.org/docs/9.4/interactive/sql-select.html Search for: join_type Imaging following situation: I want to receive two result sets from two tables, re

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread travis
Not an expert, but I would try a temporary unlogged table. Sent from my android device. -Original Message- From: Johannes To: pgsql-general@postgresql.org Sent: Mon, 08 Feb 2016 11:07 Subject: [GENERAL] execute same query only one time? Hi, is there a best practice to share data

Re: [GENERAL] execute same query only one time?

2016-02-08 Thread David G. Johnston
On Mon, Feb 8, 2016 at 12:05 PM, Johannes wrote: > Hi, > > is there a best practice to share data between two select statements? > > Imaging following situation: I want to receive two result sets from two > tables, referring to a specific id from table t0 AND I try not to query > for that specifi

[GENERAL] execute same query only one time?

2016-02-08 Thread Johannes
Hi, is there a best practice to share data between two select statements? Imaging following situation: I want to receive two result sets from two tables, referring to a specific id from table t0 AND I try not to query for that specific id a second time. Table t0 returns 1 row and table t1 return