Re: execute same query only one time? - Mailing list pgsql-general

From travis@traviswellman.com
Subject Re: execute same query only one time?
Date
Msg-id 3eec934d-374d-48ce-9b03-da48b8b42593.maildroid@localhost
Whole thread Raw
In response to execute same query only one time?  (Johannes <jotpe@posteo.de>)
Responses Re: execute same query only one time?
List pgsql-general
Not an expert, but I would try a temporary unlogged table.

Sent from my android device.

-----Original Message-----
From: Johannes <jotpe@posteo.de>
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 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

pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: execute same query only one time?
Next
From: Adrian Klaver
Date:
Subject: Re: execute same query only one time?