Re: WHERE - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: WHERE
Date
Msg-id 20050511033212.GA32672@wolff.to
Whole thread Raw
In response to WHERE  (Hrishikesh Deshmukh <hdeshmuk@gmail.com>)
List pgsql-general
On Mon, May 09, 2005 at 15:48:44 -0400,
  Hrishikesh Deshmukh <hdeshmuk@gmail.com> wrote:
> Hi All,
>
> How can one use a table created for saving the results for a query be
> used in WHERE for subsequent query!!!
>
> Step 1) create table temp as select gene from dataTable1 intersect
> select gene from dataTable2;
>
> Now temp has been created, temp has only one column which has list of
> genes and nothing else but i want to retrieve annotation for the genes
> in temp table.
>
> Is it possible to: select geneAnnotation from dataTable1 where genes =
> "gene in temp table";!!!!!

Unless you are going to reuse the table (essentailly creating a materialized
view), you should probably just do this in one statement.

SELECT geneAnnotation
  FROM dataTable1
  WHERE gene IN
    (SELECT gene FROM dataTable2)
;

In 7.4 or later this should run pretty fast. In older versions, you probably
want to use EXISTS instead of IN. This also assumes that there are no
NULL values for gene in dataTable2.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PERFORM] "Hash index" vs. "b-tree index" (PostgreSQL
Next
From: Alex Turner
Date:
Subject: Re: Adventures in Quest for GUI RAD