Re: Creating index on a view? - Mailing list pgsql-general

From Richard Huxton
Subject Re: Creating index on a view?
Date
Msg-id 41A48B9B.3010908@archonet.com
Whole thread Raw
In response to Re: Creating index on a view?  ("Net Virtual Mailing Lists" <mailinglists@net-virtual.com>)
List pgsql-general
Net Virtual Mailing Lists wrote:
>
> CREATE TABLE table2 (
>   table2_id INTEGER,
>   table2_desc VARCHAR,
>   table3_id   INTEGER[]
> );
>
> CREATE TABLE table3 (
>   table3_id INTEGER,
>   table3_desc VARCHAR
> );
>
>
> What I need is an "indirect index" (for lack of a better phrase) that
> allows me to do:
>
> SELECT b.table3_id, b.table3_desc FROM table2 a, table 3 b WHERE
> a.table2_id = 4 AND b.table3_id = ANY (a.table3_id);
>
> .. in the above example, the "4" is the variable component in the
> query...  THe table3_id in table2 has the value of '{7}' - so when I do
> the above select, it is actually retrieving records from table3 where
> table3_id is equal to 7.
[snip]
> SELECT b.table3_id, b.table3_desc FROM table3 b WHERE b.table3_id = 7;

I don't think you want to use an array here. If you were to split your
tables:
  table2 (t2_id, t2_desc);
  table3 (t3_id, t3_desc);
  table2_and_3 (t2_id, t3_id);
Then, you should find everything a lot easier.

Try not to use arrays as a set.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Neil Conway
Date:
Subject: Re: Can't get planner to use multicolumn index on large
Next
From: Richard Huxton
Date:
Subject: Re: Moving/Using Postgres Binaries on multiple machines