Re: execute same query only one time?

From: Vitaly Burovoy <vitaly(dot)burovoy(at)gmail(dot)com>
To: travis(at)traviswellman(dot)com
Cc: pgsql-general(at)postgresql(dot)org, Johannes <jotpe(at)posteo(dot)de>
Subject: Re: execute same query only one time?
Date: 2016-02-08 19:40:34
Message-ID: CAKOSWN=z36y8F1y9_nYB7pRdQZeK9-Q5RakPAc39OQr6F5c4qw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/8/16, travis(at)traviswellman(dot)com <travis(at)traviswellman(dot)com> wrote:
> Not an expert, but I would try a temporary unlogged table.

Note: temporary tables are always unlogged.

Please,
1. Don't top post.
2. Use "Reply to all" to be sure an author of an original letter gets
your answer even if he hasn't subscribed to the list.

> -----Original Message-----
> From: Johannes <jotpe(at)posteo(dot)de>
> To: pgsql-general(at)postgresql(dot)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 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 returns multiple rows.
>
> begin;
> 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 ...);
> commit;
>
> Best regards Johannes

--
Best regards,
Vitaly Burovoy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-02-08 19:40:47 Re: Let's Do the CoC Right
Previous Message Vitaly Burovoy 2016-02-08 19:32:17 Re: execute same query only one time?